Hibernate Auto-Increment not working

Posted by dharga on Stack Overflow See other posts from Stack Overflow or by dharga
Published on 2010-05-25T14:36:25Z Indexed on 2010/05/25 14:41 UTC
Read the original article Hit count: 219

Filed under:
|
|

I have a column in my DB that is set with Identity(1,1) and I can't get hibernate annotations to work for it. I get errors when I try to create a new record.

In my entity I have the following.

@GeneratedValue(strategy=GenerationType.IDENTITY, generator="native")
@Column(name="SeqNo", unique=true, nullable=false)
BigDecimal seqNo;

But when I try to add a new record I get the following error.

Cannot insert explicit value for identity column in table 'MemberSelectedOptions' when IDENTITY_INSERT is set to OFF. I don't want to set IDENTIY_INSERT to ON because I want the identity column in the db to manage the values.

The SQL that is run is the following; where you can clearly see the insert.

insert into dbo.MemberSelectedOptions 
  (OptionStatusCd, 
  EffectiveDate,
  TermDate, 
  SelectionStatusDate, 
  SysLstUpdtUserId, 
  SysLstTrxDtm, 
  SourceApplication,
  GroupId,
  MemberId, 
  OptionId, 
  SeqNo) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

What am I missing?

© Stack Overflow or respective owner

Related posts about java

Related posts about database