I previously had a table that is created using hibernate entities. I am using the hibernate import.sql method to input a bunch of data to run before my unit tests. These are all in insert statements.
Everything was working fine until a design change forced us to switch to using a generated PK instead of the old NaturalId PK. Now none of my inserts are working and hibernate is not spitting out any errors. Please help!
@Entity
@Table(name="PERSON")
@GenericGenerator(name="PERSON_SEQ", strategy = "sequence",
parameters = { @Parameter(name="sequence", value="PERSON_SEQ") } )
public class PersonEntity implements Serializable {
@Id
@GeneratedValue( strategy=GenerationType.SEQUENCE, generator="PERSON_SEQ")
@Column(name="PERSON_ID", nullable=false, updatable=false)
private Long id;
@NaturalId
@NotNull
@Min(1)
@Column(name="FIRST_NAME", nullable=false, updatable=false)
private String firstName;
//More code....
And for my insert statements…
INSERT INTO "PERSON" (PERSON_ID, FIRST_NAME, LAST_NAME, SOCIAL_SECURITY) VALUES (PERSON_SEQ.NEXTVAL, 'John', 'Doe', '111111111');
I could care less if inserting via creating a hibernate object works in this case. It’s much more important that the sql insert statements work.
Also, I have hibernate set to INFO and show sql is true, but still no error messages… Any help is greatly appreciated.
I think the issue here has to do with me unit testing in Hypersonic. I am not sure if any of you are familiar with that but that is the unit testing sql dialect my team is using. Thanks for the comments. I’ve been able to solve me issue by doing the following work-around:
Hardcode the id for certain columns with 1 for the first value and then select max(id) + 1 for each subsequent column. After all data is inserted I then increment the sequence to the proper value with the help of PL/SQL.
Thanks for your help everyone.