6

I am attempting to persist an entity with an attribute that I want to be populated from a DB sequence. I'm using Oracle, have created the sequence, verified the sequence works via sql, and yet my attribute isn't getting populated. Here's 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'm seen online show this annotation being used with @Id, but I have another attribute that I'm using for my id.

I've 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;
fmpdmb
  • 1,370
  • 3
  • 21
  • 34
  • ugh... I just realized this may be a dup: [hibernate-jpa-sequence-non-id][1] [1]: http://stackoverflow.com/questions/277630/hibernate-jpa-sequence-non-id – fmpdmb Mar 06 '13 at 16:44

2 Answers2

4

JPA only mandates support for @GeneratedValue on @Id fields. Some JPA implementations (such as DataNucleus JPA) support it but not all do.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
1

I have created a proposal for JPA to support @GeneratedValue for non-id attributes. Please vote here for this to be included in 2.2 https://java.net/jira/browse/JPA_SPEC-113

Petar Tahchiev
  • 4,336
  • 4
  • 35
  • 48