Hibernate version: version that comes with JBoss 4.0.4 GA
Mapping documents: none, annotations and EJB3 used
Name and version of the database you are using: PostgreSQL 8.1.4
I am currently experimenting with EJB3 in JBoss, and have encountered an issue with using sequences created by
@SequenceGenerator and used with the
@GeneratedValue.
Code:
@SequenceGenerator(name = "Institution_Sequence", initialValue = 1, sequenceName = "institution_seq")
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Institution_Sequence")
My entity setup is as follows Student, Course, Institution, and Location. The relationships between the entities are a
Student -> Course = Many to Many with the Course entity 'owning' the relationship
Course -> Institution = Many to Many with the Institution entity 'owning' the relationship
Institution->Location = Many to One with the with Institution 'owning' the relationship (not sure about Many to One but the Institution entity has the JoinColumn annotation)
I have a very simple driver program just to test one relationship as below:
Code:
public void populateDatabase() {
Location not = new Location();
not.setLocation("Nottingham");
mEntityManager.persist(not);
Location lon = new Location();
lon.setLocation("London");
mEntityManager.persist(lon);
Location she = new Location();
she.setLocation("Sheffield");
mEntityManager.persist(she);
Institution uni = new Institution(not);
uni.setName("Nottingham Trent University");
mEntityManager.persist(uni);
Institution uni2 = new Institution();
uni2.setName("Nottingham University");
uni2.setLocation(not);
mEntityManager.persist(uni2);
}
The program works fine, but any records inserted have the PK starting from 50, and the id of each entity is an
int datatype.
Does anyone have any idea why it is starting from 50 ? I have also checked in the DB itself and the Sequence should start from 1, plus it does not seem to get incremented correctly (increment by 1 for 3 inserts ??).
Can anyone help ?
Thanks in advance,
Andy[/code]