Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Validation Exception on compound key
Validation Exception on compound key [message #1710120] Sun, 04 October 2015 17:18 Go to next message
Zerb Lopolis is currently offline Zerb LopolisFriend
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
Re: Validation Exception on compound key [message #1710397 is a reply to message #1710120] Tue, 06 October 2015 12:38 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1379
Registered: July 2009
Senior Member
The types within the OrderBookKey IdClass definition need to be the same type as the keys of the BidOrder and AskOrder classes, not the BidOrder and AskOrder themselves. Something like:

public class OrderBookKey  implements Serializable {
	private static final long serialVersionUID = -1176849441366682537L;
	private BidOrderKey bidOrder;
	private Integer askOrder;
}


Re: Validation Exception on compound key [message #1710451 is a reply to message #1710397] Tue, 06 October 2015 19:19 Go to previous message
Zerb Lopolis is currently offline Zerb LopolisFriend
Messages: 2
Registered: October 2015
Junior Member
Thanks Chris, that helped a lot. I was a bit confused with the relationships vs the keys. It's deploying now.

Cheers,
Zerb

[Updated on: Tue, 06 October 2015 19:20]

Report message to a moderator

Previous Topic:Can I hint Eclipselink to use the shared cache after a native query
Next Topic:Cant get NamedEntityGraph to work....
Goto Forum:
  


Current Time: Fri Feb 26 04:53:43 GMT 2021

Powered by FUDForum. Page generated in 0.02001 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top