roon (1) [Avatar] Offline
#1
Hi,
I am trying to generate a new value for a non-key persisted field [SalesOrderExternalReference] using the generated value of another field but nothing much happens...

I tried various options but nothing much happens. Thanks for some pointers...

When a new SalesOrder object is created, the generated value remains at 0. The my_sequence_generator_table does not also have new values except for the original value placed by me manually.


@Entity (name="sales_order")
public class SalesOrder
{
@Column(name="sales_order_id") //key
@Id @GeneratedValue
private long id;
...
...

// tried with annotation @Id and without it, but no effect
@TableGenerator(name="mySequenceGenerator",
table="my_sequence_generator",
pkColumnName="sequence_name",
valueColumnName="sequence_value",
initialValue=1,
allocationSize=50,
pkColumnValue="sales_order_external_reference_long_value")
@GeneratedValue(strategy=GenerationType.TABLE,
generator="mySequenceGenerator")
@Column(name="sales_order_external_reference_long_value")
private long salesOrderExternalReferenceLongValue; //non-key persisted field
...

CREATE TABLE `my_sequence_generator` (
`sequence_name` varchar(80) NOT NULL,
`sequence_value` bigint(20) NOT NULL,
PRIMARY KEY (`sequence_name`)
)
...
...
@Column(name="sales_order_external_reference")
private String salesOrderExternalReference;
...
...


| sequence_name | sequence_value |
| sales_order_external_reference_long_value | 1