Mybatis Generation Clobbering Date-Timestamp Trigger

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mybatis Generation Clobbering Date-Timestamp Trigger

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 (`real_data_field`)) 

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"

    <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.
Reply | Threaded
Open this post in threaded view
|

Re: Mybatis Generation Clobbering Date-Timestamp Trigger

Jeff Butler
You can override the columns and tell the generator that they are "generated always" columns. In that case, the generator will leave those columns out of insert/update operations.


Jeff Butler


On Wed, Jul 25, 2018 at 11:00 AM Daniel Needles <[hidden email]> wrote:
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 (`real_data_field`)) 

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"

    <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.

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: Mybatis Generation Clobbering Date-Timestamp Trigger

Daniel Needles
Lol that is the missing RTFM.  Thanks man!  I'll keep working on my Google Foo.

On Wed, Jul 25, 2018 at 8:03 AM Jeff Butler <[hidden email]> wrote:
You can override the columns and tell the generator that they are "generated always" columns. In that case, the generator will leave those columns out of insert/update operations.


Jeff Butler


On Wed, Jul 25, 2018 at 11:00 AM Daniel Needles <[hidden email]> wrote:
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 (`real_data_field`)) 

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"

    <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.

--
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.


--
DANIEL L. NEEDLES
Principal Consultant
NMSGuru, Inc.
512.233.1000
[hidden email]

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: Mybatis Generation Clobbering Date-Timestamp Trigger

Daniel Needles
In reply to this post by Daniel Needles
For posterity if you read through the link and applied to my example,  I would change my XML to as follows:

FROM:
        <table schema="c" tableName="silly" domainObjectName="SillyBean">
          <generatedKey column="id" sqlStatement="MySql" identity="true" />
        </table>

TO:
        <table schema="c" tableName="silly" domainObjectName="SillyBean">
          <generatedKey column="id" sqlStatement="MySql" identity="true" />
          <columnOverride column="update_time" isGeneratedAlways="True"></columnOverride>
          <columnOverride column="create_time" isGeneratedAlways="True"></columnOverride>
        </table>


On Wednesday, July 25, 2018 at 8:00:35 AM UTC-7, Daniel Needles wrote:
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 (`real_data_field`)) 

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 "-//<a href="http://mybatis.org//DTD" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmybatis.org%2F%2FDTD\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHjp-E8UL0TmmS7A0V54yMfbtfEkA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmybatis.org%2F%2FDTD\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHjp-E8UL0TmmS7A0V54yMfbtfEkA&#39;;return true;">mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "<a href="http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmybatis.org%2Fdtd%2Fmybatis-generator-config_1_0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGbQhQcAyMHnIvI65x3b69_l8vDOQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmybatis.org%2Fdtd%2Fmybatis-generator-config_1_0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGbQhQcAyMHnIvI65x3b69_l8vDOQ&#39;;return true;">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.