Java – JPA or hibernate generates (non primary key) column values instead of starting with 1

I want a JPA / Hibernate (preferably JPA) annotation that can generate the value of a column. It is not a primary key or starts from 1

From what I've seen, JPA can't do this with @ generatedvalue and @ sequencegenerator and @ tablegenerator Or anything else

I saw an extra table in solution, and I found it not elegant

I can use hibernate annotations because I already have hibernate annotations

I want to use @ generated, but I can't make it work, people claim may

@Generated(GenerationTime.INSERT)
private long invoiceNumber;//invoice number

Update: an additional requirement. If the transaction is rolled back, we can't leave blank on the number anybody?

resolvent

Solution

@Generatedvalue applies only to identifiers, so you cannot use it If MySQL is used, it is very limited because it does not support database sequences

InnoDB doesn’t support multiple AUTO_ Increment columns if your table PK is auto_ Increased, you have two options:

>Selecting a separate table behaves like a sequence generator, and the solution you've said is not happy. > Use insert trigger to add this column

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>