JPA: using @GeneratedValue for a column without id

I am trying to save an object with an attribute that I want to populate from a database sequence. I use Oracle, created a sequence, checked the sequence through sql, and yet my attribute is not populated. Here 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 that I see on the Internet show this annotation used with @Id, but I have another attribute that I use for my id.

I 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;
+5
source share
2 answers

JPA only supports @GeneratedValue support in @Id fields. Some JPA implementations (such as DataNucleus JPA ) support it, but not all do.

+3
source

JPA @GeneratedValue id. , , 2.2 https://java.net/jira/browse/JPA_SPEC-113

0

All Articles