[jboss-user] [EJB 3.0] - Re: EJB 3 Required to Override equals & hashCode
ddurst@mechdrives.com
do-not-reply at jboss.com
Mon Nov 19 13:36:22 EST 2007
anonymous wrote :
| go for logical equality, so if your entity has three fields:
| Code:
|
| | @Id
| | @GeneratedValue
| | private int id;
| | private String firstName;
| | private String lastName;
| |
|
|
| then equals/hashCode should be based on first/lastName and not id.
|
I understand this concept as you have put forth. That being that a firstName & lastName has some uniqueness.
This issue occurs in my mind when you have 2 Joe Smiths.
These to object are then considered equal when they may not actually
be EQUAL in reality. So to then you would say add SSN or some other
unique. Which in all reality replaces the Primary key. This works for
objects with such unique identifier.
Unfortunately with objects such as a Order Line where the structure are as follows:
| @Id
| @GeneratedValue(strategy = GenerationType.SEQUENCE)
| private Long id;
| private String lineStatus = OrderLine.SHIP_WHEN_COMP;
| @Temporal(TemporalType.TIMESTAMP)
| private Calendar requiredDate;
| private LineQuantity quantity;
| @Embedded
| private PriceCost priceCost;
| @OneToOne(cascade = CascadeType.ALL)
| private Item item;
| @ManyToOne
| @JoinColumn(name="parentOrder")
| private Order parentOrder;
|
Business unique identifiers do not exist.
Two order lines where all attribute values are equal can exist on the same parent order.
Does anyone have a example of how to resolve THIS specific issue?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4106132#4106132
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4106132
More information about the jboss-user
mailing list