SequenceGenerator not working, TableGenerator is.
572079Apr 21 2008 — edited Apr 28 2008I'm able to generate keys using a sequence-table. The annotations of the PK field are:
@Id
@GeneratedValue(generator="relation.relationnr", strategy=GenerationType.TABLE)
@TableGenerator( name="relation.relationnr", pkColumnValue="relationnr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1)
@Column(name="relationnr")
But I'm not able to get the same behavior using sequences:
@Id
@SequenceGenerator( name="relation.relationnr", sequenceName="relationnr", allocationSize=1)
@GeneratedValue(generator="relation.relationnr", strategy=GenerationType.SEQUENCE)
@Column(name="relationnr")
With the second approach Toplink simply does not assing a value to the related field:
SQL errorcode: -391
SQL state: 23000
local message: Cannot insert a null into column (relation.relationnr).
java.sql.SQLException: Cannot insert a null into column (relation.relationnr).
The sequence exists:
select relationnr.nextval from _number where n = 1;
nextval
100246
Using another name for the sequence, or have the Toplink generate one, does not help.
Why isn't the sequence working?