Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate composite key id generator
    primarykey
    data
    text
    <p>I have my entities as below. My data model enforces below and I cannot change referential itegrity. So I am stuck with a composite key. I want to autogenerate/use some generator for orderId </p> <p>Yes I have read below. <a href="http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier" rel="nofollow">http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier</a></p> <p>I donot want to manage the id generation process as above recommends application generating the orderId.</p> <p>How to make the partial id generator work.. what are my options..would greatly appreciate some thoughts by experts.</p> <pre><code>@Entity @Table(name = "Orders", uniqueConstraints = @UniqueConstraint(columnNames = {"partner_ID", "order_ident" })) public class Order { private OrderId id; public Order() { } @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "partnerId", column = @Column(name = "partner_ID", nullable = false)), @AttributeOverride(name = "employeeId", column = @Column(name = "employee_ID", nullable = false)), @AttributeOverride(name = "orderId", column = @Column(name = "order_ID", nullable = false)) }) public OrderId getId() { return this.id; } public void setId(OrderId id) { this.id = id; } } @Embeddable public class OrderId extends FactObject { private int partnerId; private int employeeId; private int orderId; public OrderId() { } public OrderId(int partnerId, int employeeId, int orderId) { this.partnerId = partnerId; this.employeeId = employeeId; this.orderId = orderId; } @Column(name = "partner_ID", nullable = false) public int getpartnerId() { return this.partnerId; } public void setpartnerId(int partnerId) { this.partnerId = partnerId; } @Column(name = "employee_ID", nullable = false) public int getemployeeId() { return this.employeeId; } public void setemployeeId(int employeeId) { this.employeeId = employeeId; } @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE") @Column(name = "order_ID",insertable=false, nullable=false, updatable=false) public int getOrderId() { return this.orderId; } public void setOrderId(int orderId) { this.orderId = orderId; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof OrderId)) return false; OrderId castOther = (OrderId) other; return (this.getpartnerId() == castOther.getpartnerId()) &amp;&amp; (this.getemployeeId() == castOther.getemployeeId()) &amp;&amp; (this.getOrderId() == castOther.getOrderId()); } public int hashCode() { int result = 17; result = 37 * result + this.getpartnerId(); result = 37 * result + this.getemployeeId(); result = 37 * result + this.getOrderId(); return result; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload