"null value in column" when inserting with @selectKey

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

"null value in column" when inserting with @selectKey

gfrancis1@gmail.com
MyBatis Generator created the following statement in my
ScheduleMapper:

<insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do
not modify.
      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
    -->
    insert into public.schedule ( report_id, module,
email_recipients,  nextrun, interval_code, owner_id,  type, filename)
    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
#{email_recipients,jdbcType=VARCHAR},
      #{nextrun,jdbcType=TIMESTAMP},
#{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
      SELECT (last_value + increment_by) from  schedule_pkey_seq
    </selectKey>
  </insert>

but when I call this statement, passing in a partially-formed Schedule
object, I get an exception:
Caused by: org.postgresql.util.PSQLException: ERROR: null value in
column "schedule_id" violates not-null constraint

Does this indicate something is wrong with my Generator config?

<table schema='public' tableName='SCHEDULE'
domainObjectName='Schedule'>
 <property name='useActualColumnNames' value='true'/>
 <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
increment_by) from  schedule_pkey_seq" identity="true" />
</table>


Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
You should have identity="false" in your generator config.  This does
not appear to be an identity column.

Jeff Butler


On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:

> MyBatis Generator created the following statement in my
> ScheduleMapper:
>
> <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>    <!--
>      WARNING - @mbggenerated
>      This element is automatically generated by MyBatis Generator, do
> not modify.
>      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>    -->
>    insert into public.schedule ( report_id, module,
> email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> #{email_recipients,jdbcType=VARCHAR},
>      #{nextrun,jdbcType=TIMESTAMP},
> #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>      SELECT (last_value + increment_by) from  schedule_pkey_seq
>    </selectKey>
>  </insert>
>
> but when I call this statement, passing in a partially-formed Schedule
> object, I get an exception:
> Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> column "schedule_id" violates not-null constraint
>
> Does this indicate something is wrong with my Generator config?
>
> <table schema='public' tableName='SCHEDULE'
> domainObjectName='Schedule'>
>  <property name='useActualColumnNames' value='true'/>
>  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> increment_by) from  schedule_pkey_seq" identity="true" />
> </table>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

gfrancis1@gmail.com
thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?

On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:

> You should have identity="false" in your generator config.  This does
> not appear to be an identity column.
>
> Jeff Butler
>
>
>
>
>
>
>
> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
> > MyBatis Generator created the following statement in my
> > ScheduleMapper:
>
> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
> >    <!--
> >      WARNING - @mbggenerated
> >      This element is automatically generated by MyBatis Generator, do
> > not modify.
> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
> >    -->
> >    insert into public.schedule ( report_id, module,
> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> > #{email_recipients,jdbcType=VARCHAR},
> >      #{nextrun,jdbcType=TIMESTAMP},
> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >    </selectKey>
> >  </insert>
>
> > but when I call this statement, passing in a partially-formed Schedule
> > object, I get an exception:
> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> > column "schedule_id" violates not-null constraint
>
> > Does this indicate something is wrong with my Generator config?
>
> > <table schema='public' tableName='SCHEDULE'
> > domainObjectName='Schedule'>
> >  <property name='useActualColumnNames' value='true'/>
> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> > increment_by) from  schedule_pkey_seq" identity="true" />
> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
Right...   PK != identity.

An identity column is an autonumber column that is filled by the
database automatically on insert (like in Access or SQL Server).  I
believe you are using a sequence.

Jeff Butler




On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:

> thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>
> On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>> You should have identity="false" in your generator config.  This does
>> not appear to be an identity column.
>>
>> Jeff Butler
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>> > MyBatis Generator created the following statement in my
>> > ScheduleMapper:
>>
>> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>> >    <!--
>> >      WARNING - @mbggenerated
>> >      This element is automatically generated by MyBatis Generator, do
>> > not modify.
>> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>> >    -->
>> >    insert into public.schedule ( report_id, module,
>> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> > #{email_recipients,jdbcType=VARCHAR},
>> >      #{nextrun,jdbcType=TIMESTAMP},
>> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >    </selectKey>
>> >  </insert>
>>
>> > but when I call this statement, passing in a partially-formed Schedule
>> > object, I get an exception:
>> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>> > column "schedule_id" violates not-null constraint
>>
>> > Does this indicate something is wrong with my Generator config?
>>
>> > <table schema='public' tableName='SCHEDULE'
>> > domainObjectName='Schedule'>
>> >  <property name='useActualColumnNames' value='true'/>
>> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>> > increment_by) from  schedule_pkey_seq" identity="true" />
>> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

gfrancis1@gmail.com
Hmm, now my mapping for Insert is:
  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do
not modify.
      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
    -->
    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
      SELECT (last_value + increment_by) from  schedule_pkey_seq
    </selectKey>
    insert into public.schedule (schedule_id, report_id, module,
      email_recipients, nextrun, interval_code,
      owner_id, type, filename
      )
    values (#{schedule_id,jdbcType=BIGINT},
#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
      #{email_recipients,jdbcType=VARCHAR},
#{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
#{filename,jdbcType=VARCHAR}
      )
  </insert>

But when I call it I get:
SqlSession operation; SQL []; ERROR: null value in column
"schedule_id" violates not-null constraint;

Any ideas what I'm doing wring?



On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:

> Right...   PK != identity.
>
> An identity column is an autonumber column that is filled by the
> database automatically on insert (like in Access or SQL Server).  I
> believe you are using a sequence.
>
> Jeff Butler
>
>
>
>
>
>
>
> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>
> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
> >> You should have identity="false" in your generator config.  This does
> >> not appear to be an identity column.
>
> >> Jeff Butler
>
> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
> >> > MyBatis Generator created the following statement in my
> >> > ScheduleMapper:
>
> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
> >> >    <!--
> >> >      WARNING - @mbggenerated
> >> >      This element is automatically generated by MyBatis Generator, do
> >> > not modify.
> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
> >> >    -->
> >> >    insert into public.schedule ( report_id, module,
> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >> > #{email_recipients,jdbcType=VARCHAR},
> >> >      #{nextrun,jdbcType=TIMESTAMP},
> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >> >    </selectKey>
> >> >  </insert>
>
> >> > but when I call this statement, passing in a partially-formed Schedule
> >> > object, I get an exception:
> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> >> > column "schedule_id" violates not-null constraint
>
> >> > Does this indicate something is wrong with my Generator config?
>
> >> > <table schema='public' tableName='SCHEDULE'
> >> > domainObjectName='Schedule'>
> >> >  <property name='useActualColumnNames' value='true'/>
> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> >> > increment_by) from  schedule_pkey_seq" identity="true" />
> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
This mapper looks better to me.  Could it be that the select statement
is not returning a value?  It would be good to turn on MyBatis logging
and watch what's coming back from the database.

Jeff Butler


On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:

> Hmm, now my mapping for Insert is:
>  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
>    <!--
>      WARNING - @mbggenerated
>      This element is automatically generated by MyBatis Generator, do
> not modify.
>      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
>    -->
>    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
>      SELECT (last_value + increment_by) from  schedule_pkey_seq
>    </selectKey>
>    insert into public.schedule (schedule_id, report_id, module,
>      email_recipients, nextrun, interval_code,
>      owner_id, type, filename
>      )
>    values (#{schedule_id,jdbcType=BIGINT},
> #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>      #{email_recipients,jdbcType=VARCHAR},
> #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
>      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
> #{filename,jdbcType=VARCHAR}
>      )
>  </insert>
>
> But when I call it I get:
> SqlSession operation; SQL []; ERROR: null value in column
> "schedule_id" violates not-null constraint;
>
> Any ideas what I'm doing wring?
>
>
>
> On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
>> Right...   PK != identity.
>>
>> An identity column is an autonumber column that is filled by the
>> database automatically on insert (like in Access or SQL Server).  I
>> believe you are using a sequence.
>>
>> Jeff Butler
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
>> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>>
>> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>> >> You should have identity="false" in your generator config.  This does
>> >> not appear to be an identity column.
>>
>> >> Jeff Butler
>>
>> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>> >> > MyBatis Generator created the following statement in my
>> >> > ScheduleMapper:
>>
>> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>> >> >    <!--
>> >> >      WARNING - @mbggenerated
>> >> >      This element is automatically generated by MyBatis Generator, do
>> >> > not modify.
>> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>> >> >    -->
>> >> >    insert into public.schedule ( report_id, module,
>> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >> > #{email_recipients,jdbcType=VARCHAR},
>> >> >      #{nextrun,jdbcType=TIMESTAMP},
>> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >> >    </selectKey>
>> >> >  </insert>
>>
>> >> > but when I call this statement, passing in a partially-formed Schedule
>> >> > object, I get an exception:
>> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>> >> > column "schedule_id" violates not-null constraint
>>
>> >> > Does this indicate something is wrong with my Generator config?
>>
>> >> > <table schema='public' tableName='SCHEDULE'
>> >> > domainObjectName='Schedule'>
>> >> >  <property name='useActualColumnNames' value='true'/>
>> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>> >> > increment_by) from  schedule_pkey_seq" identity="true" />
>> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

gfrancis1@gmail.com
26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
insert into public.schedule ( report_id, module, interval_code,
owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
test2(String)

If I do the following in PgAmin: SELECT (last_value + increment_by)
from  schedule_pkey_seq
I get: 48

Is there something else I should be looking at?

On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:

> This mapper looks better to me.  Could it be that the select statement
> is not returning a value?  It would be good to turn on MyBatis logging
> and watch what's coming back from the database.
>
> Jeff Butler
>
>
>
>
>
>
>
> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
> > Hmm, now my mapping for Insert is:
> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
> >    <!--
> >      WARNING - @mbggenerated
> >      This element is automatically generated by MyBatis Generator, do
> > not modify.
> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
> >    -->
> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >    </selectKey>
> >    insert into public.schedule (schedule_id, report_id, module,
> >      email_recipients, nextrun, interval_code,
> >      owner_id, type, filename
> >      )
> >    values (#{schedule_id,jdbcType=BIGINT},
> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >      #{email_recipients,jdbcType=VARCHAR},
> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
> > #{filename,jdbcType=VARCHAR}
> >      )
> >  </insert>
>
> > But when I call it I get:
> > SqlSession operation; SQL []; ERROR: null value in column
> > "schedule_id" violates not-null constraint;
>
> > Any ideas what I'm doing wring?
>
> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
> >> Right...   PK != identity.
>
> >> An identity column is an autonumber column that is filled by the
> >> database automatically on insert (like in Access or SQL Server).  I
> >> believe you are using a sequence.
>
> >> Jeff Butler
>
> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>
> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
> >> >> You should have identity="false" in your generator config.  This does
> >> >> not appear to be an identity column.
>
> >> >> Jeff Butler
>
> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
> >> >> > MyBatis Generator created the following statement in my
> >> >> > ScheduleMapper:
>
> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
> >> >> >    <!--
> >> >> >      WARNING - @mbggenerated
> >> >> >      This element is automatically generated by MyBatis Generator, do
> >> >> > not modify.
> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
> >> >> >    -->
> >> >> >    insert into public.schedule ( report_id, module,
> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >> >> > #{email_recipients,jdbcType=VARCHAR},
> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >> >> >    </selectKey>
> >> >> >  </insert>
>
> >> >> > but when I call this statement, passing in a partially-formed Schedule
> >> >> > object, I get an exception:
> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> >> >> > column "schedule_id" violates not-null constraint
>
> >> >> > Does this indicate something is wrong with my Generator config?
>
> >> >> > <table schema='public' tableName='SCHEDULE'
> >> >> > domainObjectName='Schedule'>
> >> >> >  <property name='useActualColumnNames' value='true'/>
> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
> >> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
This log doesn't match the new mapper you sent earlier (the inserted
column list doesn't match what you sent before).  Something weird is
going on - maybe you have old versions of the XML files hanging
around?

Jeff



On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:

> 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
> insert into public.schedule ( report_id, module, interval_code,
> owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
> 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
> 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
> test2(String)
>
> If I do the following in PgAmin: SELECT (last_value + increment_by)
> from  schedule_pkey_seq
> I get: 48
>
> Is there something else I should be looking at?
>
> On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
>> This mapper looks better to me.  Could it be that the select statement
>> is not returning a value?  It would be good to turn on MyBatis logging
>> and watch what's coming back from the database.
>>
>> Jeff Butler
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
>> > Hmm, now my mapping for Insert is:
>> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
>> >    <!--
>> >      WARNING - @mbggenerated
>> >      This element is automatically generated by MyBatis Generator, do
>> > not modify.
>> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
>> >    -->
>> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
>> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >    </selectKey>
>> >    insert into public.schedule (schedule_id, report_id, module,
>> >      email_recipients, nextrun, interval_code,
>> >      owner_id, type, filename
>> >      )
>> >    values (#{schedule_id,jdbcType=BIGINT},
>> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >      #{email_recipients,jdbcType=VARCHAR},
>> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
>> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
>> > #{filename,jdbcType=VARCHAR}
>> >      )
>> >  </insert>
>>
>> > But when I call it I get:
>> > SqlSession operation; SQL []; ERROR: null value in column
>> > "schedule_id" violates not-null constraint;
>>
>> > Any ideas what I'm doing wring?
>>
>> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
>> >> Right...   PK != identity.
>>
>> >> An identity column is an autonumber column that is filled by the
>> >> database automatically on insert (like in Access or SQL Server).  I
>> >> believe you are using a sequence.
>>
>> >> Jeff Butler
>>
>> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
>> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>>
>> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>> >> >> You should have identity="false" in your generator config.  This does
>> >> >> not appear to be an identity column.
>>
>> >> >> Jeff Butler
>>
>> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>> >> >> > MyBatis Generator created the following statement in my
>> >> >> > ScheduleMapper:
>>
>> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>> >> >> >    <!--
>> >> >> >      WARNING - @mbggenerated
>> >> >> >      This element is automatically generated by MyBatis Generator, do
>> >> >> > not modify.
>> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>> >> >> >    -->
>> >> >> >    insert into public.schedule ( report_id, module,
>> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >> >> > #{email_recipients,jdbcType=VARCHAR},
>> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
>> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >> >> >    </selectKey>
>> >> >> >  </insert>
>>
>> >> >> > but when I call this statement, passing in a partially-formed Schedule
>> >> >> > object, I get an exception:
>> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>> >> >> > column "schedule_id" violates not-null constraint
>>
>> >> >> > Does this indicate something is wrong with my Generator config?
>>
>> >> >> > <table schema='public' tableName='SCHEDULE'
>> >> >> > domainObjectName='Schedule'>
>> >> >> >  <property name='useActualColumnNames' value='true'/>
>> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
>> >> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

gfrancis1@gmail.com
sorry, I just pasted the log from insertSelective() instead of
insert()
if you need it,
log from insert() is:

26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==>  Executing:
insert into public.schedule (schedule_id, report_id, module,
email_recipients, nextrun, interval_code, owner_id, type, filename )
values (?, ?, ?, ?, ?, ?, ?, ?, ? )
26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==> Parameters:
null, 1(Integer), 2(String), null, null, 0(Integer), 999(Integer),
0(Integer), test2(String)

On Oct 26, 4:37 pm, Jeff Butler <[hidden email]> wrote:

> This log doesn't match the new mapper you sent earlier (the inserted
> column list doesn't match what you sent before).  Something weird is
> going on - maybe you have old versions of the XML files hanging
> around?
>
> Jeff
>
>
>
>
>
>
>
> On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:
> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
> > insert into public.schedule ( report_id, module, interval_code,
> > owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
> > 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
> > test2(String)
>
> > If I do the following in PgAmin: SELECT (last_value + increment_by)
> > from  schedule_pkey_seq
> > I get: 48
>
> > Is there something else I should be looking at?
>
> > On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
> >> This mapper looks better to me.  Could it be that the select statement
> >> is not returning a value?  It would be good to turn on MyBatis logging
> >> and watch what's coming back from the database.
>
> >> Jeff Butler
>
> >> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
> >> > Hmm, now my mapping for Insert is:
> >> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
> >> >    <!--
> >> >      WARNING - @mbggenerated
> >> >      This element is automatically generated by MyBatis Generator, do
> >> > not modify.
> >> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
> >> >    -->
> >> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >> >    </selectKey>
> >> >    insert into public.schedule (schedule_id, report_id, module,
> >> >      email_recipients, nextrun, interval_code,
> >> >      owner_id, type, filename
> >> >      )
> >> >    values (#{schedule_id,jdbcType=BIGINT},
> >> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >> >      #{email_recipients,jdbcType=VARCHAR},
> >> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
> >> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
> >> > #{filename,jdbcType=VARCHAR}
> >> >      )
> >> >  </insert>
>
> >> > But when I call it I get:
> >> > SqlSession operation; SQL []; ERROR: null value in column
> >> > "schedule_id" violates not-null constraint;
>
> >> > Any ideas what I'm doing wring?
>
> >> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
> >> >> Right...   PK != identity.
>
> >> >> An identity column is an autonumber column that is filled by the
> >> >> database automatically on insert (like in Access or SQL Server).  I
> >> >> believe you are using a sequence.
>
> >> >> Jeff Butler
>
> >> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
> >> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>
> >> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
> >> >> >> You should have identity="false" in your generator config.  This does
> >> >> >> not appear to be an identity column.
>
> >> >> >> Jeff Butler
>
> >> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
> >> >> >> > MyBatis Generator created the following statement in my
> >> >> >> > ScheduleMapper:
>
> >> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
> >> >> >> >    <!--
> >> >> >> >      WARNING - @mbggenerated
> >> >> >> >      This element is automatically generated by MyBatis Generator, do
> >> >> >> > not modify.
> >> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
> >> >> >> >    -->
> >> >> >> >    insert into public.schedule ( report_id, module,
> >> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
> >> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >> >> >> > #{email_recipients,jdbcType=VARCHAR},
> >> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
> >> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
> >> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
> >> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
> >> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >> >> >> >    </selectKey>
> >> >> >> >  </insert>
>
> >> >> >> > but when I call this statement, passing in a partially-formed Schedule
> >> >> >> > object, I get an exception:
> >> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> >> >> >> > column "schedule_id" violates not-null constraint
>
> >> >> >> > Does this indicate something is wrong with my Generator config?
>
> >> >> >> > <table schema='public' tableName='SCHEDULE'
> >> >> >> > domainObjectName='Schedule'>
> >> >> >> >  <property name='useActualColumnNames' value='true'/>
> >> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> >> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
> >> >> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
Before this in the log, you should see an "Executing:" statement with
your select next value query.  If you don't see it, then your select
key isn't executing and that's the problem.

Jeff


On Tue, Oct 26, 2010 at 3:40 PM, blackfrancis <[hidden email]> wrote:

> sorry, I just pasted the log from insertSelective() instead of
> insert()
> if you need it,
> log from insert() is:
>
> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==>  Executing:
> insert into public.schedule (schedule_id, report_id, module,
> email_recipients, nextrun, interval_code, owner_id, type, filename )
> values (?, ?, ?, ?, ?, ?, ?, ?, ? )
> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==> Parameters:
> null, 1(Integer), 2(String), null, null, 0(Integer), 999(Integer),
> 0(Integer), test2(String)
>
> On Oct 26, 4:37 pm, Jeff Butler <[hidden email]> wrote:
>> This log doesn't match the new mapper you sent earlier (the inserted
>> column list doesn't match what you sent before).  Something weird is
>> going on - maybe you have old versions of the XML files hanging
>> around?
>>
>> Jeff
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:
>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
>> > insert into public.schedule ( report_id, module, interval_code,
>> > owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
>> > 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
>> > test2(String)
>>
>> > If I do the following in PgAmin: SELECT (last_value + increment_by)
>> > from  schedule_pkey_seq
>> > I get: 48
>>
>> > Is there something else I should be looking at?
>>
>> > On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
>> >> This mapper looks better to me.  Could it be that the select statement
>> >> is not returning a value?  It would be good to turn on MyBatis logging
>> >> and watch what's coming back from the database.
>>
>> >> Jeff Butler
>>
>> >> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
>> >> > Hmm, now my mapping for Insert is:
>> >> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
>> >> >    <!--
>> >> >      WARNING - @mbggenerated
>> >> >      This element is automatically generated by MyBatis Generator, do
>> >> > not modify.
>> >> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
>> >> >    -->
>> >> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
>> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >> >    </selectKey>
>> >> >    insert into public.schedule (schedule_id, report_id, module,
>> >> >      email_recipients, nextrun, interval_code,
>> >> >      owner_id, type, filename
>> >> >      )
>> >> >    values (#{schedule_id,jdbcType=BIGINT},
>> >> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >> >      #{email_recipients,jdbcType=VARCHAR},
>> >> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
>> >> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
>> >> > #{filename,jdbcType=VARCHAR}
>> >> >      )
>> >> >  </insert>
>>
>> >> > But when I call it I get:
>> >> > SqlSession operation; SQL []; ERROR: null value in column
>> >> > "schedule_id" violates not-null constraint;
>>
>> >> > Any ideas what I'm doing wring?
>>
>> >> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
>> >> >> Right...   PK != identity.
>>
>> >> >> An identity column is an autonumber column that is filled by the
>> >> >> database automatically on insert (like in Access or SQL Server).  I
>> >> >> believe you are using a sequence.
>>
>> >> >> Jeff Butler
>>
>> >> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
>> >> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>>
>> >> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>> >> >> >> You should have identity="false" in your generator config.  This does
>> >> >> >> not appear to be an identity column.
>>
>> >> >> >> Jeff Butler
>>
>> >> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>> >> >> >> > MyBatis Generator created the following statement in my
>> >> >> >> > ScheduleMapper:
>>
>> >> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>> >> >> >> >    <!--
>> >> >> >> >      WARNING - @mbggenerated
>> >> >> >> >      This element is automatically generated by MyBatis Generator, do
>> >> >> >> > not modify.
>> >> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>> >> >> >> >    -->
>> >> >> >> >    insert into public.schedule ( report_id, module,
>> >> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>> >> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >> >> >> > #{email_recipients,jdbcType=VARCHAR},
>> >> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
>> >> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>> >> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>> >> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>> >> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >> >> >> >    </selectKey>
>> >> >> >> >  </insert>
>>
>> >> >> >> > but when I call this statement, passing in a partially-formed Schedule
>> >> >> >> > object, I get an exception:
>> >> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>> >> >> >> > column "schedule_id" violates not-null constraint
>>
>> >> >> >> > Does this indicate something is wrong with my Generator config?
>>
>> >> >> >> > <table schema='public' tableName='SCHEDULE'
>> >> >> >> > domainObjectName='Schedule'>
>> >> >> >> >  <property name='useActualColumnNames' value='true'/>
>> >> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>> >> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
>> >> >> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
Ahhh...I think I just figured it out.

Change your <selectKey> statement so that it includes order="BEFORE"

This may be a bug in the generator.  You can change your
generatorConfig so that <generatedKey> has type="pre" - this should
fix it on future generation runs.


Jeff


On Tue, Oct 26, 2010 at 4:09 PM, Jeff Butler <[hidden email]> wrote:

> Before this in the log, you should see an "Executing:" statement with
> your select next value query.  If you don't see it, then your select
> key isn't executing and that's the problem.
>
> Jeff
>
>
> On Tue, Oct 26, 2010 at 3:40 PM, blackfrancis <[hidden email]> wrote:
>> sorry, I just pasted the log from insertSelective() instead of
>> insert()
>> if you need it,
>> log from insert() is:
>>
>> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==>  Executing:
>> insert into public.schedule (schedule_id, report_id, module,
>> email_recipients, nextrun, interval_code, owner_id, type, filename )
>> values (?, ?, ?, ?, ?, ?, ?, ?, ? )
>> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==> Parameters:
>> null, 1(Integer), 2(String), null, null, 0(Integer), 999(Integer),
>> 0(Integer), test2(String)
>>
>> On Oct 26, 4:37 pm, Jeff Butler <[hidden email]> wrote:
>>> This log doesn't match the new mapper you sent earlier (the inserted
>>> column list doesn't match what you sent before).  Something weird is
>>> going on - maybe you have old versions of the XML files hanging
>>> around?
>>>
>>> Jeff
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:
>>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
>>> > insert into public.schedule ( report_id, module, interval_code,
>>> > owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
>>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
>>> > 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
>>> > test2(String)
>>>
>>> > If I do the following in PgAmin: SELECT (last_value + increment_by)
>>> > from  schedule_pkey_seq
>>> > I get: 48
>>>
>>> > Is there something else I should be looking at?
>>>
>>> > On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
>>> >> This mapper looks better to me.  Could it be that the select statement
>>> >> is not returning a value?  It would be good to turn on MyBatis logging
>>> >> and watch what's coming back from the database.
>>>
>>> >> Jeff Butler
>>>
>>> >> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
>>> >> > Hmm, now my mapping for Insert is:
>>> >> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
>>> >> >    <!--
>>> >> >      WARNING - @mbggenerated
>>> >> >      This element is automatically generated by MyBatis Generator, do
>>> >> > not modify.
>>> >> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
>>> >> >    -->
>>> >> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
>>> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>>> >> >    </selectKey>
>>> >> >    insert into public.schedule (schedule_id, report_id, module,
>>> >> >      email_recipients, nextrun, interval_code,
>>> >> >      owner_id, type, filename
>>> >> >      )
>>> >> >    values (#{schedule_id,jdbcType=BIGINT},
>>> >> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>>> >> >      #{email_recipients,jdbcType=VARCHAR},
>>> >> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
>>> >> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
>>> >> > #{filename,jdbcType=VARCHAR}
>>> >> >      )
>>> >> >  </insert>
>>>
>>> >> > But when I call it I get:
>>> >> > SqlSession operation; SQL []; ERROR: null value in column
>>> >> > "schedule_id" violates not-null constraint;
>>>
>>> >> > Any ideas what I'm doing wring?
>>>
>>> >> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
>>> >> >> Right...   PK != identity.
>>>
>>> >> >> An identity column is an autonumber column that is filled by the
>>> >> >> database automatically on insert (like in Access or SQL Server).  I
>>> >> >> believe you are using a sequence.
>>>
>>> >> >> Jeff Butler
>>>
>>> >> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
>>> >> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>>>
>>> >> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>>> >> >> >> You should have identity="false" in your generator config.  This does
>>> >> >> >> not appear to be an identity column.
>>>
>>> >> >> >> Jeff Butler
>>>
>>> >> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>>> >> >> >> > MyBatis Generator created the following statement in my
>>> >> >> >> > ScheduleMapper:
>>>
>>> >> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>>> >> >> >> >    <!--
>>> >> >> >> >      WARNING - @mbggenerated
>>> >> >> >> >      This element is automatically generated by MyBatis Generator, do
>>> >> >> >> > not modify.
>>> >> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>>> >> >> >> >    -->
>>> >> >> >> >    insert into public.schedule ( report_id, module,
>>> >> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>>> >> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>>> >> >> >> > #{email_recipients,jdbcType=VARCHAR},
>>> >> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
>>> >> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>>> >> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>>> >> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>>> >> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>>> >> >> >> >    </selectKey>
>>> >> >> >> >  </insert>
>>>
>>> >> >> >> > but when I call this statement, passing in a partially-formed Schedule
>>> >> >> >> > object, I get an exception:
>>> >> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>>> >> >> >> > column "schedule_id" violates not-null constraint
>>>
>>> >> >> >> > Does this indicate something is wrong with my Generator config?
>>>
>>> >> >> >> > <table schema='public' tableName='SCHEDULE'
>>> >> >> >> > domainObjectName='Schedule'>
>>> >> >> >> >  <property name='useActualColumnNames' value='true'/>
>>> >> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>>> >> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
>>> >> >> >> > </table>
>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

gfrancis1@gmail.com
success!
I hope my plight can be used by the Generator committers (is that
you?) and save future generations ;)
Thanks for your help!

On Oct 26, 5:16 pm, Jeff Butler <[hidden email]> wrote:

> Ahhh...I think I just figured it out.
>
> Change your <selectKey> statement so that it includes order="BEFORE"
>
> This may be a bug in the generator.  You can change your
> generatorConfig so that <generatedKey> has type="pre" - this should
> fix it on future generation runs.
>
> Jeff
>
>
>
>
>
>
>
> On Tue, Oct 26, 2010 at 4:09 PM, Jeff Butler <[hidden email]> wrote:
> > Before this in the log, you should see an "Executing:" statement with
> > your select next value query.  If you don't see it, then your select
> > key isn't executing and that's the problem.
>
> > Jeff
>
> > On Tue, Oct 26, 2010 at 3:40 PM, blackfrancis <[hidden email]> wrote:
> >> sorry, I just pasted the log from insertSelective() instead of
> >> insert()
> >> if you need it,
> >> log from insert() is:
>
> >> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==>  Executing:
> >> insert into public.schedule (schedule_id, report_id, module,
> >> email_recipients, nextrun, interval_code, owner_id, type, filename )
> >> values (?, ?, ?, ?, ?, ?, ?, ?, ? )
> >> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==> Parameters:
> >> null, 1(Integer), 2(String), null, null, 0(Integer), 999(Integer),
> >> 0(Integer), test2(String)
>
> >> On Oct 26, 4:37 pm, Jeff Butler <[hidden email]> wrote:
> >>> This log doesn't match the new mapper you sent earlier (the inserted
> >>> column list doesn't match what you sent before).  Something weird is
> >>> going on - maybe you have old versions of the XML files hanging
> >>> around?
>
> >>> Jeff
>
> >>> On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:
> >>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
> >>> > insert into public.schedule ( report_id, module, interval_code,
> >>> > owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
> >>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
> >>> > 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
> >>> > test2(String)
>
> >>> > If I do the following in PgAmin: SELECT (last_value + increment_by)
> >>> > from  schedule_pkey_seq
> >>> > I get: 48
>
> >>> > Is there something else I should be looking at?
>
> >>> > On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
> >>> >> This mapper looks better to me.  Could it be that the select statement
> >>> >> is not returning a value?  It would be good to turn on MyBatis logging
> >>> >> and watch what's coming back from the database.
>
> >>> >> Jeff Butler
>
> >>> >> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
> >>> >> > Hmm, now my mapping for Insert is:
> >>> >> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
> >>> >> >    <!--
> >>> >> >      WARNING - @mbggenerated
> >>> >> >      This element is automatically generated by MyBatis Generator, do
> >>> >> > not modify.
> >>> >> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
> >>> >> >    -->
> >>> >> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
> >>> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >>> >> >    </selectKey>
> >>> >> >    insert into public.schedule (schedule_id, report_id, module,
> >>> >> >      email_recipients, nextrun, interval_code,
> >>> >> >      owner_id, type, filename
> >>> >> >      )
> >>> >> >    values (#{schedule_id,jdbcType=BIGINT},
> >>> >> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >>> >> >      #{email_recipients,jdbcType=VARCHAR},
> >>> >> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
> >>> >> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
> >>> >> > #{filename,jdbcType=VARCHAR}
> >>> >> >      )
> >>> >> >  </insert>
>
> >>> >> > But when I call it I get:
> >>> >> > SqlSession operation; SQL []; ERROR: null value in column
> >>> >> > "schedule_id" violates not-null constraint;
>
> >>> >> > Any ideas what I'm doing wring?
>
> >>> >> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
> >>> >> >> Right...   PK != identity.
>
> >>> >> >> An identity column is an autonumber column that is filled by the
> >>> >> >> database automatically on insert (like in Access or SQL Server).  I
> >>> >> >> believe you are using a sequence.
>
> >>> >> >> Jeff Butler
>
> >>> >> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
> >>> >> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>
> >>> >> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
> >>> >> >> >> You should have identity="false" in your generator config.  This does
> >>> >> >> >> not appear to be an identity column.
>
> >>> >> >> >> Jeff Butler
>
> >>> >> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
> >>> >> >> >> > MyBatis Generator created the following statement in my
> >>> >> >> >> > ScheduleMapper:
>
> >>> >> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
> >>> >> >> >> >    <!--
> >>> >> >> >> >      WARNING - @mbggenerated
> >>> >> >> >> >      This element is automatically generated by MyBatis Generator, do
> >>> >> >> >> > not modify.
> >>> >> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
> >>> >> >> >> >    -->
> >>> >> >> >> >    insert into public.schedule ( report_id, module,
> >>> >> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
> >>> >> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
> >>> >> >> >> > #{email_recipients,jdbcType=VARCHAR},
> >>> >> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
> >>> >> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
> >>> >> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
> >>> >> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
> >>> >> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
> >>> >> >> >> >    </selectKey>
> >>> >> >> >> >  </insert>
>
> >>> >> >> >> > but when I call this statement, passing in a partially-formed Schedule
> >>> >> >> >> > object, I get an exception:
> >>> >> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
> >>> >> >> >> > column "schedule_id" violates not-null constraint
>
> >>> >> >> >> > Does this indicate something is wrong with my Generator config?
>
> >>> >> >> >> > <table schema='public' tableName='SCHEDULE'
> >>> >> >> >> > domainObjectName='Schedule'>
> >>> >> >> >> >  <property name='useActualColumnNames' value='true'/>
> >>> >> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
> >>> >> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
> >>> >> >> >> > </table>
Reply | Threaded
Open this post in threaded view
|

Re: "null value in column" when inserting with @selectKey

Jeff Butler
Great!  I'm working on a fix or "behavior modification" for the generator now.

This is related to a change in behavior between iBATIS and MyBatis
that I hadn't noticed before.

Thanks for reporting this!

Jeff


On Tue, Oct 26, 2010 at 4:35 PM, blackfrancis <[hidden email]> wrote:

> success!
> I hope my plight can be used by the Generator committers (is that
> you?) and save future generations ;)
> Thanks for your help!
>
> On Oct 26, 5:16 pm, Jeff Butler <[hidden email]> wrote:
>> Ahhh...I think I just figured it out.
>>
>> Change your <selectKey> statement so that it includes order="BEFORE"
>>
>> This may be a bug in the generator.  You can change your
>> generatorConfig so that <generatedKey> has type="pre" - this should
>> fix it on future generation runs.
>>
>> Jeff
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Oct 26, 2010 at 4:09 PM, Jeff Butler <[hidden email]> wrote:
>> > Before this in the log, you should see an "Executing:" statement with
>> > your select next value query.  If you don't see it, then your select
>> > key isn't executing and that's the problem.
>>
>> > Jeff
>>
>> > On Tue, Oct 26, 2010 at 3:40 PM, blackfrancis <[hidden email]> wrote:
>> >> sorry, I just pasted the log from insertSelective() instead of
>> >> insert()
>> >> if you need it,
>> >> log from insert() is:
>>
>> >> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==>  Executing:
>> >> insert into public.schedule (schedule_id, report_id, module,
>> >> email_recipients, nextrun, interval_code, owner_id, type, filename )
>> >> values (?, ?, ?, ?, ?, ?, ?, ?, ? )
>> >> 26 Oct 2010 16:39:47,942 DEBUG [PreparedStatement] ==> Parameters:
>> >> null, 1(Integer), 2(String), null, null, 0(Integer), 999(Integer),
>> >> 0(Integer), test2(String)
>>
>> >> On Oct 26, 4:37 pm, Jeff Butler <[hidden email]> wrote:
>> >>> This log doesn't match the new mapper you sent earlier (the inserted
>> >>> column list doesn't match what you sent before).  Something weird is
>> >>> going on - maybe you have old versions of the XML files hanging
>> >>> around?
>>
>> >>> Jeff
>>
>> >>> On Tue, Oct 26, 2010 at 3:28 PM, blackfrancis <[hidden email]> wrote:
>> >>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==>  Executing:
>> >>> > insert into public.schedule ( report_id, module, interval_code,
>> >>> > owner_id, type, filename ) values ( ?, ?, ?, ?, ?, ? )
>> >>> > 26 Oct 2010 16:25:10,386 DEBUG [PreparedStatement] ==> Parameters:
>> >>> > 1(Integer), 2(String), 0(Integer), 999(Integer), 0(Integer),
>> >>> > test2(String)
>>
>> >>> > If I do the following in PgAmin: SELECT (last_value + increment_by)
>> >>> > from  schedule_pkey_seq
>> >>> > I get: 48
>>
>> >>> > Is there something else I should be looking at?
>>
>> >>> > On Oct 26, 2:45 pm, Jeff Butler <[hidden email]> wrote:
>> >>> >> This mapper looks better to me.  Could it be that the select statement
>> >>> >> is not returning a value?  It would be good to turn on MyBatis logging
>> >>> >> and watch what's coming back from the database.
>>
>> >>> >> Jeff Butler
>>
>> >>> >> On Tue, Oct 26, 2010 at 8:56 AM, blackfrancis <[hidden email]> wrote:
>> >>> >> > Hmm, now my mapping for Insert is:
>> >>> >> >  <insert id="insert" parameterType="com.myco.myprod.model.Schedule">
>> >>> >> >    <!--
>> >>> >> >      WARNING - @mbggenerated
>> >>> >> >      This element is automatically generated by MyBatis Generator, do
>> >>> >> > not modify.
>> >>> >> >      This element was generated on Mon Oct 25 19:48:27 EDT 2010.
>> >>> >> >    -->
>> >>> >> >    <selectKey keyProperty="schedule_id" resultType="java.lang.Long">
>> >>> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >>> >> >    </selectKey>
>> >>> >> >    insert into public.schedule (schedule_id, report_id, module,
>> >>> >> >      email_recipients, nextrun, interval_code,
>> >>> >> >      owner_id, type, filename
>> >>> >> >      )
>> >>> >> >    values (#{schedule_id,jdbcType=BIGINT},
>> >>> >> > #{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >>> >> >      #{email_recipients,jdbcType=VARCHAR},
>> >>> >> > #{nextrun,jdbcType=TIMESTAMP}, #{interval_code,jdbcType=INTEGER},
>> >>> >> >      #{owner_id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
>> >>> >> > #{filename,jdbcType=VARCHAR}
>> >>> >> >      )
>> >>> >> >  </insert>
>>
>> >>> >> > But when I call it I get:
>> >>> >> > SqlSession operation; SQL []; ERROR: null value in column
>> >>> >> > "schedule_id" violates not-null constraint;
>>
>> >>> >> > Any ideas what I'm doing wring?
>>
>> >>> >> > On Oct 25, 4:09 pm, Jeff Butler <[hidden email]> wrote:
>> >>> >> >> Right...   PK != identity.
>>
>> >>> >> >> An identity column is an autonumber column that is filled by the
>> >>> >> >> database automatically on insert (like in Access or SQL Server).  I
>> >>> >> >> believe you are using a sequence.
>>
>> >>> >> >> Jeff Butler
>>
>> >>> >> >> On Mon, Oct 25, 2010 at 3:05 PM, blackfrancis <[hidden email]> wrote:
>> >>> >> >> > thanks, but Schedule_id is the PK.  Do you mean PK != 'identity' ?
>>
>> >>> >> >> > On Oct 25, 3:53 pm, Jeff Butler <[hidden email]> wrote:
>> >>> >> >> >> You should have identity="false" in your generator config.  This does
>> >>> >> >> >> not appear to be an identity column.
>>
>> >>> >> >> >> Jeff Butler
>>
>> >>> >> >> >> On Mon, Oct 25, 2010 at 2:47 PM, blackfrancis <[hidden email]> wrote:
>> >>> >> >> >> > MyBatis Generator created the following statement in my
>> >>> >> >> >> > ScheduleMapper:
>>
>> >>> >> >> >> > <insert id="insert" parameterType="com.myco.myprod.model.Schedule" >
>> >>> >> >> >> >    <!--
>> >>> >> >> >> >      WARNING - @mbggenerated
>> >>> >> >> >> >      This element is automatically generated by MyBatis Generator, do
>> >>> >> >> >> > not modify.
>> >>> >> >> >> >      This element was generated on Thu Oct 21 10:33:08 EDT 2010.
>> >>> >> >> >> >    -->
>> >>> >> >> >> >    insert into public.schedule ( report_id, module,
>> >>> >> >> >> > email_recipients,  nextrun, interval_code, owner_id,  type, filename)
>> >>> >> >> >> >    values (#{report_id,jdbcType=INTEGER}, #{module,jdbcType=VARCHAR},
>> >>> >> >> >> > #{email_recipients,jdbcType=VARCHAR},
>> >>> >> >> >> >      #{nextrun,jdbcType=TIMESTAMP},
>> >>> >> >> >> > #{interval_code,jdbcType=INTEGER}, #{owner_id,jdbcType=INTEGER},
>> >>> >> >> >> >      #{type,jdbcType=INTEGER}, #{filename,jdbcType=VARCHAR})
>> >>> >> >> >> >    <selectKey resultType="java.lang.Long" keyProperty="schedule_id" >
>> >>> >> >> >> >      SELECT (last_value + increment_by) from  schedule_pkey_seq
>> >>> >> >> >> >    </selectKey>
>> >>> >> >> >> >  </insert>
>>
>> >>> >> >> >> > but when I call this statement, passing in a partially-formed Schedule
>> >>> >> >> >> > object, I get an exception:
>> >>> >> >> >> > Caused by: org.postgresql.util.PSQLException: ERROR: null value in
>> >>> >> >> >> > column "schedule_id" violates not-null constraint
>>
>> >>> >> >> >> > Does this indicate something is wrong with my Generator config?
>>
>> >>> >> >> >> > <table schema='public' tableName='SCHEDULE'
>> >>> >> >> >> > domainObjectName='Schedule'>
>> >>> >> >> >> >  <property name='useActualColumnNames' value='true'/>
>> >>> >> >> >> >  <generatedKey column="SCHEDULE_ID" sqlStatement="SELECT (last_value +
>> >>> >> >> >> > increment_by) from  schedule_pkey_seq" identity="true" />
>> >>> >> >> >> > </table>