I have a model called Totals
@Entity
public class Totals extends Model{
@EmbeddedId
private TotalsPK id;
public Totals(TotalsPK key, Integer _count)
{
id = key;
count = _count;
}
public static Finder<TotalsPK,Totals> find = new Finder<TotalsPK, Totals> (
TotalsPK.class, Totals.class
);
public static Totals find(TotalsPK id)
{
//try this way instead of relying on find.byId working..... same error though!
return find.where().eq("user_id", id.getUserId()).eq("item_id", id.getItemId()).findUnique();
// return find.byId(id);
}
........... etc
And then I have my key class
@Embeddable
public class TotalsPK {
private Long userId;
private Long itemId;
public TotalsPK(Long _userId, Long _itemId)
{
userId = _userId;
itemId = _itemId;
}
public boolean equals(Object rhs)
{
return (userId.equals(((TotalsPK)rhs).getUserId()) && itemId.equals(((TotalsPK)rhs).getItemId()));
}
public int hashCode()
{
//from Effective Java Chapter 3
int result = (int) (userId ^ (userId >>> 32));
result = 31 * result + (int) (itemId ^ (itemId >>> 32));
return result;
}
This works fine when searching for a record which doesnt exist, but when searching for one that does exist the object passed to "equals" from Ebean is null and I have no idea why this is, any ideas what I am doing wrong here?
Null checking the rhs value passed into equals stops it crashing, but the equals check is never hit
thanks