JPA: use @ generatedvalue on non ID columns

I try to stick to an entity with attributes I want to populate from the DB sequence I am using Oracle to create a sequence and verify the working principle of the sequence through SQL, but my attributes are not filled This is what I have:

@GeneratedValue(generator = "RFQ_LINE_IDS_SEQUENCE",strategy=GenerationType.SEQUENCE)
@SequenceGenerator(name="RFQ_LINE_IDS_SEQUENCE",sequenceName="RFQ_LINE_IDS_SEQUENCE",allocationSize=1000000000)
@Column(name = "external_line_item_id")
private String externalLineItemId;

All the examples I see on the Internet show that this annotation is used with @ ID, but I have another attribute. I'm using my ID

I have also tried the following to no avail:

@GeneratedValue(generator = "RFQ_LINE_IDS_SEQUENCE",strategy=GenerationType.SEQUENCE)
@GenericGenerator(name = "RFQ_LINE_IDS_SEQUENCE",strategy = "sequence",parameters = {@Parameter(name = "sequence",value = "RFQ_LINE_IDS_SEQUENCE")})
@Column(name = "external_line_item_id")
private String externalLineItemId;

Solution

JPA only forces @ generatedvalue on the @ ID field Some JPA implementations (such as datanucleus JPA) support it, but not all support it

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
分享
二维码
< <上一篇
下一篇>>