The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

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