Conflicts withl Date-timestamp Triggers and Mybatis Generator

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Conflicts withl Date-timestamp Triggers and Mybatis Generator

Daniel Needles
I might have missed the RTFM/link, so please redirect if so, but my Google Foo is failing me today.

I have a simple table with simple needs and date-timestamp triggers:

    CREATE TABLE IF NOT EXISTS `silly`.`table` (
      `real_data_field` VARCHAR(45) NOT NULL,
      `create_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
      `update_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
      PRIMARY KEY (`host_id`, `region`)) 

I generate via mvn mybatis-generator:generate but when the program runs, Mybatis clobbers the create_time and update_time to NULL.  It looks like there is an Ignore option available in the XML BUT I want to query with these field.   As a workaround I can commented out these fields for create_time and update_time in the XML insert and update functions, then the code worked fine.  But I'd rather not have to hack and rehack these autogenerated files every time.  Given I didn't find anything on this topic either way, I suspect I am missing something basic as I am new to Mybatis.  Could anyone provide any enlightenment?

Here's the XML for the Generator if it helps:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

    <generatorConfiguration>
      <classPathEntry location="/home/user/lib/mysql-connector-java-5.1.22.jar" />
      <context id="CTbls" targetRuntime="MyBatis3">
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/c"
                        userId="USER" password="PASS">
            <property name="nullCatalogMeansCurrent" value="true"/>
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--  in command line environment  -->
        <javaModelGenerator targetPackage="com.nmsguru.c.deployservice.db.model" targetProject="/home/i2user/REPO/i2deploy/c/deploy-service/common/src/main/java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <sqlMapGenerator targetPackage="com.nmsguru.c.deployservice.db.xml"  targetProject="/home/i2user/REPO/i2deploy/c/deploy-service/common/src/main/java">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.nmsguru.c.deployservice.db.mapper"  targetProject="/home/i2user/REPO/i2deploy/c/deploy-service/common/src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <!--  in eclipse environment
       <javaModelGenerator targetPackage="com.nmsguru.c.deployservice.db.model" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="com.nmsguru.c.deployservice.db.xml" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.nmsguru.c.deployservice.db.mapper"
                             targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        -->
        <table schema="c" tableName="silly" domainObjectName="SillyBean">
          <generatedKey column="id" sqlStatement="MySql" identity="true" />
        </table>


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.