-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cannot insert explicit value for identity column
PostPosted: Sat Jan 20, 2007 12:04 am 
Newbie

Joined: Fri Jan 19, 2007 11:44 pm
Posts: 3
I am failed to insert record into the table by using hibernate.
Please check my code. Many thanks.

***sql command generated by hibernate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insert into PRODUCT_CATEGORY (STORE_ID, CAT_ID) values (?, ?)


***my expected sql command should be
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insert into PRODUCT_CATEGORY (STORE_ID) values (?)


***error message
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF


***following is my table definition
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CREATE TABLE [PRODUCT_CATEGORY] (
[STORE_ID] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[CAT_ID] [decimal](18, 0) IDENTITY (1, 1) NOT NULL ,
CONSTRAINT [PK_PRODUCT_CATEGORY] PRIMARY KEY CLUSTERED
(
[STORE_ID],
[CAT_ID]
) ON [PRIMARY]
) ON [PRIMARY]
GO


***following is my code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Entity
@Table(name="PRODUCT_CATEGORY")
@IdClass(ProductCategoryKey.class)
public class ProductCategory implements java.io.Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getCatId() {
return this.catId;
}

@Id
public String getStoreId() {
return storeId;
}
}

@Embeddable
public class ProductCategoryKey implements Serializable{
@Column(name="STORE_ID")
public String getStoreId() {
return storeId;
}

@Column(name="CAT_ID")
public Long getCatId() {
return catId;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 9:58 am 
Newbie

Joined: Wed May 16, 2007 7:39 am
Posts: 5
We had this problem once and the cause was simply due to duplicate specification of the same column in the schema file.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.