سؤال

Today my DB responsible boss told me that I'm using a wrong sequence, in JPA/Hibernate, but I weren't so I checked up on why my generated table entries had a higher ID than the normal(trigger) generated entries.
And I found This on SO which is horrific for me, since I use this DB sequence in DB triggers to generate entries. Which means, as far as I know. That in 50x time My DB will start to hit the sequence numbers generated by my Java application.

To avoid this, I need to use the specific sequence, and not the sequence*50. But havn't found out how to do this, can anyone help me?

Thanks in advance

currently it is defined like this:

@Id
@Column(name = "PVP_COST_ELEMENTS_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "wtStatSEQ")
@SequenceGenerator(name = "wtStatSEQ", sequenceName = "warehouse.wt_stat_SEQ")
هل كانت مفيدة؟

المحلول

In hibernate you can specify the used seq explicitly by using the annotations

@Id
@Column(name = "COLUMN_NAME", nullable = false)
@GeneratedValue(strategy = AUTO, generator = "yourEntitySeqGen")
@SequenceGenerator(name = "yourEntitySeqGen", sequenceName = "SEQUENCE_NAME_IN_YOUR_DATABASE")

cheers

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top