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;
}
}
|