Validation Exception on compound key [message #1710120] |
Sun, 04 October 2015 17:18 |
Zerb Lopolis Messages: 2 Registered: October 2015 |
Junior Member |
|
|
Hello, I'm trying to use a compound key with user defined types, but I'm getting a ValidationException and I'm not sure why. This is the code:
public class OrderBookKey implements Serializable {
private static final long serialVersionUID = -1176849441366682537L;
private BidOrder bidOrder;
private AskOrder askOrder;
public OrderBookKey()
{
}
public BidOrder getBidOrder() {
return bidOrder;
}
public void setBidOrder(BidOrder bidOrder) {
this.bidOrder = bidOrder;
}
public AskOrder getAskOrder() {
return askOrder;
}
public void setAskOrder(AskOrder askOrder) {
this.askOrder = askOrder;
}
@Override
public int hashCode() {
return ((this.getBidOrder() == null ? 0 : this.getBidOrder().hashCode()) ^ (this.getAskOrder().hashCode()));
}
@Override
public boolean equals(Object otherOb) {
if (this == otherOb) {
return true;
}
if (!(otherOb instanceof OrderBookKey)) {
return false;
}
OrderBookKey other = (OrderBookKey) otherOb;
return ((this.getBidOrder() == null
? other.getBidOrder() == null : this.getBidOrder()
.equals(other.getBidOrder()))
&& (this.getAskOrder() == other.getAskOrder()));
}
}
And the entity:
@IdClass(OrderBookKey.class)
@Entity
@Table(name="OrderBook")
@NamedQueries({
@NamedQuery(
name="findAllOrderBooks",
query="SELECT o FROM OrderBook o " +
"ORDER BY o"
),
@NamedQuery(
name="findOrderByBid",
query="SELECT bo FROM BidOrder bo " +
"WHERE bo.member = :member"
),
@NamedQuery(
name="findOrderByAsk",
query="SELECT ao FROM AskOrder ao " +
"WHERE ao.member = :member"
)
})
public class OrderBook implements java.io.Serializable {
private static final long serialVersionUID = -5908845608956132632L;
private char status;
@Temporal(TIMESTAMP)
private Date lastUpdate;
private Integer amount;
private AskOrder askOrder;
private BidOrder bidOrder;
public OrderBook()
{
this.lastUpdate = new Date();
}
public OrderBook(Integer amount, BidOrder bidOrder, AskOrder askOrder)
{
this.lastUpdate = new Date();
this.amount = amount;
this.askOrder = askOrder;
this.bidOrder = bidOrder;
}
public char getStatus() {
return status;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public void setStatus(char status) {
this.status = status;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
@Id
@Column(nullable=false)
@ManyToOne
public BidOrder getBidOrder() {
return bidOrder;
}
public void setBidOrder(BidOrder bidOrder) {
this.bidOrder = bidOrder;
}
@Id
@Column(nullable=false)
@ManyToOne
public AskOrder getAskOrder() {
return askOrder;
}
public void setAskOrder(BidOrder bidOrder) {
this.bidOrder = bidOrder;
}
}
And this is the exception I get:
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [politse] failed.
Internal Exception: Exception [EclipseLink-7150] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [entity.OrderBookKey] and those of the entity bean class [class entity.OrderBook] must correspond and their types must be the same. Also, ensure that you have specified ID elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.. Please see server.log for more details.
But I can't see any issues with the entity naming or the key. Can anyone see where I'm going wrong?
Thanks,
Zerb
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03776 seconds