-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @CollectionId on a List. Equals fails. PersistentIdentifier
PostPosted: Sun Aug 28, 2011 5:06 pm 
Newbie

Joined: Wed Sep 03, 2008 9:56 am
Posts: 6
Hi Users,

I've configured the following List in my Entity:

Code:
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name="KW_TARGET_OPERATION_TEMPLATE_XREF", joinColumns={ @JoinColumn(name = "TARGET_OPERATION_ID") }, inverseJoinColumns={ @JoinColumn(name="TEMPLATE_ID", referencedColumnName="TARGETING_TEMPLATE_ID") })
    @GenericGenerator(name="TARGET_OPERATION_TEMPLATE_XREF_GENERATOR", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {@Parameter(name = "sequence_name", value = "KOBE_MART_TBLS.KW_TARGET_OPERATION_TEMPLATE__TARGET_OPERATION_TEMPLATE_XRE_SEQ")})
    @CollectionId(columns = @Column(name = "TARGET_OPERATION_TEMPLATE_XREF_ID"), type = @Type(type = "long"), generator = "TARGET_OPERATION_TEMPLATE_XREF_GENERATOR")
    private List<TargetingTemplateVO> templates = new ArrayList<TargetingTemplateVO>();


Now, when implementing a simple equals (with special care for the id) I fail on the templates List as the List returns as a PersistentIdentiferBag which does not override equals..

This looks very common to me but I did not find any blog posting on this.

What am I missing?

Thanks a lot,

David


Top
 Profile  
 
 Post subject: Re: @CollectionId on a List. Equals fails. PersistentIdentifier
PostPosted: Mon Aug 29, 2011 7:29 am 
Newbie

Joined: Wed Sep 03, 2008 9:56 am
Posts: 6
So here is what I was missing when spending a lot of time overcoming this problem.

Hibernate value objects are not pure POJOs as unlike POJO they have a state which means they may be transient (before save them to the database) or persistent (after saving them to the database).

This means that their equals method does not work as the ordinary deep comparison we do with pure POJOs.

For PersistentIdentifierBag a decision was made not to override equals to make sure a calling equals would not fetch an hierarchy and make it an EAGER one.

This means that we should treat Hibernate Objects as database rows. By that I mean that we should compare them by their business keys (lots of stuff about that in documentation but somehow I skipped it). If two object are of the same class and have the same primary key we treat them as same objects.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.