Hi,
I am trying to create a sequence as a primary key. The issue is that instead of incrementing by 1, it gets incremented by 50, though I have not specified that number anywhere. I tried in both derby and oracle. But the same result. So, I feel the problem could be with my code. Please help.
Code:
@Entity
@Table(name = "PERSON")
@SequenceGenerator(name = "Person_Id_Sequence", initialValue = 1, sequenceName = "Person_Id_Sequence")
public class Person {
private String firstName;
private String lastName;
private Integer personId;
private Timestamp lastUpdated;
protected Person() {
}
public Person(PersonVO personVO) {
this.setFirstName(personVO.getFirstName());
populateAttributes(personVO);
}
public void populateAttributes(PersonVO personVO) {
this.setLastName(personVO.getLastName());
}
@Column(name = "FIRST_NAME", nullable = true, length = 35)
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name = "LAST_NAME", nullable = true, length = 35)
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Id
//@GeneratedValue(strategy = GenerationType.AUTO, generator = "Person_Id_Sequence")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Person_Id_Sequence")
@Column(name = "PER_ID")
public Integer getPersonId() {
return personId;
}
public void setPersonId(Integer personId) {
this.personId = personId;
}
@Version
@Column(name = "LAST_UPDATED")
public Timestamp getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated) {
this.lastUpdated = lastUpdated;
}
}
and my hibernate.cfg.xml has the following entries
Code:
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@N7553:1521:ORCL </property>
<property name="connection.username">ips</property>
<property name="connection.password">ips</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- Mapping classes -->
<mapping class="Person" />
</session-factory>
</hibernate-configuration>