MyBatis Generator: generate mappers with autoincrement fields that work both with Mysql and HSQLDB -
i'm using mybatis generator generate mappers mysql database. have tables autoincrement fields , have declared them 'generatedkey' , work intended.
now want use hsqldb create in-memory database junit tests. have enabled mysql syntax of hsqldb mappers don't work because statement generated getting last value of autoincrement fields not compatibile.
this configuration file of mybatis generator:
<generatorconfiguration> <classpathentry location="d:\mysql-connector-java-5.1.29.jar" /> <context id="mysql" targetruntime="mybatis3"> <plugin type="org.mybatis.generator.plugins.serializableplugin"> <property name="suppressjavainterface" value="false"/> </plugin> <jdbcconnection driverclass="com.mysql.jdbc.driver" connectionurl="xxxxxxxxxxxxxxxxxxxxxx" userid="xxxxx" password="xxxxx"> </jdbcconnection> <javamodelgenerator targetpackage="it.test.dbtablesdto" targetproject="src\main\java"> <property name="enablesubpackages" value="true" /> <property name="trimstrings" value="true" /> </javamodelgenerator> <sqlmapgenerator targetpackage="it.test.dbtables" targetproject="src\main\resources"> <property name="enablesubpackages" value="true" /> </sqlmapgenerator> <javaclientgenerator targetpackage="it.test.dbtables" type="xmlmapper" targetproject="src\main\java"> <property name="enablesubpackages" value="true" /> </javaclientgenerator> <table tablename="history" schema="hist"> <generatedkey column="id_history" sqlstatement="mysql"/> </table> </context>
i have tried change value of sqlstatement in "jdbc" written in manual value doesn't work neither mysql nor hsqldb.
this mapper generated sqlstatement="mysql" (i have deleted rows not interesting):
<insert id="insert" parametertype="it.xxxx.history"> <!-- warning - @mbggenerated element automatically generated mybatis generator, not modify. element generated on wed jun 25 10:44:25 cest 2014. --> <selectkey keyproperty="idhistory" resulttype="java.lang.long"> select last_insert_id() </selectkey> insert history( ) values ( )
as can see "select last_insert_id()" statement not compatible hypersonic.
any idea?
try creating own function in hsqldb.
create function last_insert_id() returns bigint return identity();
Comments
Post a Comment