-->
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: Eager ElementsCollections on eager fetched collection
PostPosted: Tue Apr 26, 2011 5:21 am 
Newbie

Joined: Tue Apr 26, 2011 4:47 am
Posts: 4
Hi,

We are working with Hebrnate 3.6 (Java 6, Weblogic 10.3.4, Oracle 11).
We have the following entities in our system:
BaseUser, which have eager fetched pockets collection (OneToMany with mappedBy on pockets -pocket has FK and ManyToOne reference to consumer). Pocket entity have eager fetched ElementsCollections which contains pocket locks - map of the lock types and the locks details.

The problem:
When the BaseUser (specifically a consumer which extends BaseUser) is read from DB, it is read with it's pockets and their locks. If we have one consumer with one pocket, having 2 locks - then thequery returns 1*2*2 results - and the consumer pockets list is initialized with 2(!) pockets instead of one. Each pocket is brought several times - according to the number of locks it has.
As a workaround we changed the locks to be read lazily and this solved the problem, but this cause other problems for us.

The entities definitions are below:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class BaseUser extends ModelEntity {
@OneToMany(mappedBy="user",fetch=FetchType.EAGER)
private final Collection<Pocket> pockets = new ArrayList<Pocket>();


@Entity
@Table(name="POCKETS")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class Pocket extends ModelEntity {

@ManyToOne(fetch=FetchType.LAZY)
protected BaseUser user;

@ElementCollection(fetch=FetchType.Eager)
@CollectionTable(name="locks",joinColumns={@JoinColumn(name="pocket_id")})
@MapKeyEnumerated(EnumType.STRING)
@MapKeyColumn(name="lockType")
private Map<LockType,Lock> locks;

The query that is executed when the locks are read eagerly is:
/* load trivnet.core.model.consumer.Consumer */ select
consumer0_.id as id8_1_,
consumer0_.version as version8_1_,
pockets1_.user_id as user33_8_3_,
pockets1_.id as id3_,
pockets1_.id as id5_0_,
pockets1_.version as version5_0_,

pockets1_.dtype as dtype5_0_,
locks2_.pocket_id as pocket6_5_4_,
locks2_.lock_reason_time_map as lock2_4_,
locks2_.locked as locked4_,
locks2_.lock_type as lock4_4_
from
( select
id,
version,
from
consumers ) consumer0_
left outer join
pockets pockets1_
on consumer0_.id=pockets1_.user_id
left outer join
locks locks2_
on pockets1_.id=locks2_.pocket_id
where
consumer0_.id=?


When changing the locks to be read lazily the query that is exceuted is :
/* load trivnet.core.model.consumer.Consumer */ select
consumer0_.id as id16_1_,
consumer0_.version as version16_1_,
pockets1_.user_id as user33_16_3_,
pockets1_.id as id3_,
pockets1_.id as id1_0_,
pockets1_.version as version1_0_,
pockets1_.dtype as dtype1_0_
from
( select
id,
version
from
consumers ) consumer0_
left outer join
pockets pockets1_
on consumer0_.id=pockets1_.user_id
where
consumer0_.id=?

and then an extra query for the locks.

Is anyone familaire with this problem? should I opren a bug for it?

thanks,
Tovi


Top
 Profile  
 
 Post subject: Re: Eager ElementsCollections on eager fetched collection
PostPosted: Mon May 09, 2011 5:19 am 
Newbie

Joined: Thu May 05, 2011 6:33 am
Posts: 16
I'm not sure on the solution but I think that MapKeyEnumerated and MapKeyColumn are exclusive.

http://www.objectdb.com/api/java/jpa/MapKeyEnumerated

http://www.objectdb.com/api/java/jpa/MapKeyColumn

So, I will try to remove MapKeyEnumerated annotation e retry the test.

_________________
Luca Preziati


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.