when persisting an entity with auto generated PK in JPA

143 views Asked by At
@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

Column(name = "CNTNR_SHPMNT_NUM")

@XmlAttribute(name = "cntnrShpmntNum")

private Long cntnrShpmntNum;

I have a Table with name CNTNR and I made its primary key as generated with identity but its not working for me in JPA.Giving sql error-503 which says trying to insert a auto generated column.and when I tried with Column(name = "CNTNR_SHPMNT_NUM",insertable=false) its working for me but its not passing the generated value Back.The entity object giving me null as returned even the row inserted in table.

1

There are 1 answers

0
Aaron Digulla On

Add private long id; between @GeneratedValue(...) and @Column(...) since you probably don't want the column CNTNR_SHPMNT_NUM to be both a value and a PK.