Problems encountered in using MyBatis and summary

Problems encountered

The following error

org.springframework.dao.DataIntegrityViolationException:
### Error querying database. Cause: java.sql.SQLException: ORA-00911: 无效字符

### The error may exist in file [D:\Project_1\reactiveDispose\dist\classes\est\e6300\reactivedispose\dao\impl\MonitorRateDaoImpl.xml]
### The error may involve est.e6300.reactivedispose.dao.impl.MonitorRateDaoImpl.monitorNumForDline-Inline
### The error occurred while setting parameters
### SQL: select count(*) from est_pw_device device left join est_cim_disttrans disttrans on disttrans.id = device.disttransid left join est_cim_dline dline on dline.id = disttrans.dlineid inner join est_pw_terminal terminal on terminal.id = device.terminalid where dline.id = ? and (device.status = 1 or device.status = 4) and device.valid = 1;
### Cause: java.sql.SQLException: ORA-00911: 无效字符

; SQL []; ORA-00911 : invalid character
; nested exception is java.sql.SQLException: ORA- 00911: invalid character

Solution: Remove the xml file Dao's SQL statements at the end of the semicolon ";"

 

to sum up

MyBatis in Dao xml file Notes

1. General placeholders $ or # is not the cause of the problem, of course, recommended #

parameterType 2. xml set is java.lang.Long, still can pass Map, and functioning

3. xml in the end not to take ";"

4. If the result is a plurality of return, receives a List, the resultType type element should be disposed of, rather than the type of the collection

The "MyBatis-3-User-Guide" says: resultType: The fully qualified class name or alias for the expected type that will be returned from this statement. Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself. Use resultType OR resultMap, not both.

5. .xml using SQL code label multiplexing manner

SQL useless when the label

<select id="findUserById" resultType="com.lcy.entity.User">
    SELECT
     id,username,password,age,phone,email
    FROM t_user
    WHERE
    id=#{id}
</select>

 

After using the SQL tag

<sql id="userColumns"> id,username,password,age,phone,email </sql>

<select id="findUserById" resultType="com.lcy.entity.User">
    SELECT
    <include refid="userColumns"></include>
    FROM t_user
    WHERE
    id=#{id}
</select>

Guess you like

Origin www.cnblogs.com/lichuanyan/p/12131701.html