I have a mapping class using JPA annotations, and I want it to use two separate sequences for two fields:
@Entity
@Table(name="my_table", schema="schema")
@SequenceGenerator(name="sequence",sequenceName="schema.local_key_sequence")
@SequenceGenerator(name="orderSequen开发者_JAVA百科ce",sequenceName="schema.message_received_sequence")
public class MyClass
{
@Id
@Column(name="unique_key",unique=true)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence")
private long id;
@Column(name="sequence_received")
@GeneratedValue( strategy = GenerationType.SEQUENCE,generator="orderSequence" )
private long sequenceReceived;
[...]
}
However, JPA forbids me from having to @SequenceGenerator
in the Entity. How should I do this.
Note: for clarification, I want the ID to be generated automatically from the next value of local_key_sequence
, and sequenceReceived to be generated autonatically from message_received_sequence
.
You can use Generated by database value on Primary keys only.
However Hibernate (Hibernate Annotations project) can support this if only field sequenceReceived will be also Id (part of composite Id).
精彩评论