-->
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.  [ 4 posts ] 
Author Message
 Post subject: Confounding PersistentSet issue
PostPosted: Fri Jan 25, 2013 6:34 pm 
Newbie

Joined: Mon Jan 14, 2013 4:07 pm
Posts: 17
Is it possible for this state to exist in PersistentSet?

Code:
false == values.contains( values.iterator().next() );


Because I am getting this state for some reason. A have a Set where I remove a bunch of values. All of them get removed except for one. I don't know why and I can't narrow it down to something reproducible. In other test cases this works fine but I have a particular test case where all but one item is successfully removed.

The odd part is for the item that could not be removed that if I iterate through the set it shows one element, and in fact it reports a size of 1. But if I ask the set if it contains the value it says "no". Oh, and the statement "values.remove( value )" returns FALSE even though I can see that value in the PersistentSet entries.

Any thoughts?

BTW, this uses an ElementCollection in the entity with a Set of an embeddable class. If I do this, it works:

Code:
        Set<MyValue> values = new HashSet<>( entity.getValues() );
        for ( Iterator<MyValue> it = candidates.iterator(); it.hasNext(); ) {
            MyValue value = it.next();
            if ( shouldDelete( value ) ) {
                Asserts.that( values.contains( value ), "Huh?" );
                it.remove();
            }
        }

        entity.setValues( values );



However, if I remove the new HashSet creation and use the values Set directly and remove the line "entity.setValues" I will get "Huh?" printed out at some point. When I look in the debugger, the value that the set lost track of seems to be the very first entry in the backing HashSet. But the set doesn't think its there even though it is.


Top
 Profile  
 
 Post subject: Re: Confounding PersistentSet issue
PostPosted: Fri Jan 25, 2013 10:23 pm 
Newbie

Joined: Mon Jan 14, 2013 4:07 pm
Posts: 17
I have read that this problem can exist with eagerly loaded stuff. I don't think that is the case here. The entity with the @ElementCollection has lazy fetching for the collection. The embeddable class does have a OneToOne mapping to an entity and that value IS used for calculating equals and hashCode but changing that fetch type to Lazy makes no difference. Also, most of the time it is right. There is only one case (I don't know why) where the hashCode is calculated incorrectly.

Btw, is it kind of a ghost town around here? Are there other JPA implementations people are mostly using with more active communities?


Top
 Profile  
 
 Post subject: Re: Confounding PersistentSet issue
PostPosted: Mon Jan 28, 2013 3:42 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Which version of hiberante do you use?
Personally I never had this kind of problem, but I suspect it could have to do something with proxies.
Could you please test, if the iterated element is a proxy?

Code:
System.out.println("is proxy: " + values.iterator().next() instanceof HibernateProxy));



Anyway the best is to reproduce the problem in a small environment so that you could provide a junit test case.


Top
 Profile  
 
 Post subject: Re: Confounding PersistentSet issue
PostPosted: Mon Feb 11, 2013 3:47 am 
Newbie

Joined: Mon Jan 14, 2013 4:07 pm
Posts: 17
This was a programming error on my part. My hash and equals methods were not as stable as I thought they were.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.