posted 13 years ago
Hi
i want to increment a non primary key column by 1 every time a s new row is inserted.
We can generate and increment the primary key using these annotations
@Id
@SequenceGenerator(name = "generator", sequenceName = "some_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
@Column(name = "id", unique = true, nullable = false)
@NotNull
public Long getId() {
return this.id;
}
but the same does not work on some other column of the same table
@SequenceGenerator(name = "generator", sequenceName = "some_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
@Column(name = "otherColumn", unique = true, nullable = false)
@NotNull
public Long getOtherColumn() {
return this.otherColumn;
}
---> this is not working; on saving the object Hibernate throws this excpetion - org.hibernate.PropertyValueException: not-null property references a null or transient value: ...which mean the no value was generated for other column.
I m stuck with this. Please advise a solution.
Thanks!