Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: cannot simultaneously fetch multiple bags
PostPosted: Mon May 15, 2006 11:01 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Trying to upgrade to H. EntityManager / H. Annotations 3.2.0CR2 (on jboss4.0.4GA).

Previously versions were working fine.

Entities "bind" as usual.

Then:

Code:
19:51:33,248 INFO  [SessionFactoryImpl] building session factory
19:51:44,025 WARN  [ServiceController] Problem starting service persistence.units:ear=bm-test-all.ear,jar=bm-core.ejb3.jar,unitName=bright
org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
        at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
        at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:75)
        at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:43)
        at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:98)
        at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1666)
        at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1670)
        at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:2767)


Any ideas on where to look next? I'm not clear on what "multiple bags" might even be referring to.

Thanks,

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 6:01 am 
Newbie

Joined: Tue May 16, 2006 5:43 am
Posts: 5
I think I have the very same problem. I am using Hibernate 3.2 CR2, Hibernate Annotations 3.2.0 CR1 + Hibernate Entiry Manager 3.2.0 CR1.
I am not using JBoss. Database is MySQL.

Here is the log:

Code:
May 16, 2006 11:21:55 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
May 16, 2006 11:21:55 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
May 16, 2006 11:21:56 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
May 16, 2006 11:21:56 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 16, 2006 11:21:56 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 16, 2006 11:21:56 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 16, 2006 11:21:56 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 16, 2006 11:21:56 AM net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/C:/Tools/hibernate-3.2/lib/ehcache-1.2.jar!/ehcache-failsafe.xml


And than the following exception occurs.

Code:
javax.persistence.PersistenceException: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
   at com.momega.agency.console.MainTest.testSimple(MainTest.java:23)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
   at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
   at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:75)
   at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:43)
   at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:33)
   at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:103)
   at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1666)
   at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1670)
   at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:2767)
   at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:2760)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:287)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
   at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
   ... 17 more


The previous versions Hibernate 3.2.CR1 + Annotation Beta 9, Entity Manager Beta 7 works fine.

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 5:06 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Workaround can be found in this thread:

http://www.jboss.com/index.html?module= ... ic&t=82946


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 3:13 am 
Newbie

Joined: Wed Feb 15, 2006 10:39 am
Posts: 6
rdewell wrote:
Workaround can be found in this thread:

http://www.jboss.com/index.html?module= ... ic&t=82946


Hmm. Interesting. I thought FetchType.EAGER is the default behavior anyway. Is it just the bug in annotations or in the engine?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 9:12 pm 
Newbie

Joined: Tue May 16, 2006 5:43 am
Posts: 5
I have followed the link in the JBoss forum and it really helps me a lot. Thankx.
Quote:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=82946

I have removed all my FetchType.EAGER from all OneToMany relations and it works.

But can someone explain me why? I've checked release notes for hibernate but I haven't found any note about this feature. Why it worked in previous version and in the current version all fetchtype.eager have to removed?[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 2:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It did *not* work in previous versions - it resulted in bags that could contain redundant elements because of the cartesian product.

People did not realize that so now we are forcefully complaining when you specify that on queries/mappings.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The main problem is that bag semantic (through Collection or List (wo @IndexColumn) ) is way overused.
95% of collections should really be a Set

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 1:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It is overused because there is no alternative collection that does not force an initialization when you add an element.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 4:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I disagree, people don't even know that

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 20, 2006 10:09 pm 
Newbie

Joined: Fri Nov 11, 2005 12:29 pm
Posts: 3
I removed all EAGER fetch Types on collections and sets - but the sessionFactory still gives me the error:

org.hibernate.HibernateException: cannot simultaneously fetch multiple
bags
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)

the exception doesnt tell me on which entity mapping the exception is thrown. for what else but fetch=FetchType.EAGER can i search to solve the problem?

thanks in advance
-- felix


Last edited by felixgonschorek on Tue Dec 01, 2009 4:34 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Same problem (edited) Please respond?
PostPosted: Sun May 21, 2006 10:56 pm 
Beginner
Beginner

Joined: Thu Oct 16, 2003 7:25 pm
Posts: 38
Location: New York City
I also have removed all fetch=FetchType=EAGER from my @OneToMany annotations, and still get the error. I am using Hib3.2.0CR2 w HibAnn3.2.0CR1 and HibEntMan3.2.0CR1.

Also, I really was depending on the OneToMany EAGER fetching. All of my collections with OneToMany are defined as SortedSet. Once I can get the program running again, ie. once the issue above has been remedied, how do I go about getting these things to be fetched EAGERly?

<edit>
I discovered the same issue occurs for @ManyToMany associations as well. So, removing the fetch=FetchType.EAGER from both got rid of the error. However, I still need these things to be fetched eagerly, and as of now, I've got no idea how to declare that without errors.

I have tried @Fetch(FetchMode.JOIN) and I have tried @LazyCollection(LazyCollectionOption.FALSE). Short of writing my own annotation to force these collections to be initialized during the open session, is there any working way to declare these collections not lazy?
</edit>

Tom Harris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 8:13 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi,
I wrote about this issue in my blog, I try to explain why hibernate forbids
simultaneously bags fetching

This is the link
http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html

Eyal Lupu

_________________
-----------
Eyal Lupu
Blog:http://blog.eyallupu.com/
(Old blog: http://www.jroller.com/eyallupu)


Last edited by eyall on Mon Aug 16, 2010 1:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 1:30 pm 
Newbie

Joined: Tue Jan 11, 2005 12:58 pm
Posts: 15
I was getting the same issue but I was able to solve it using the following.

before:
Code:
@OneToMany(fetch= FetchType.EAGER)
    @JoinTable(name = "COUNTRY_BONUS", joinColumns =  {
        @JoinColumn(name = "COUNTRYID", referencedColumnName = "COUNTRYID")
    }, inverseJoinColumns =  {
        @JoinColumn(name = "BONUSID", referencedColumnName = "BONUSID")
    })
    private Collection<Bonus> bonuses = new ArrayList<Bonus>();


after:
Code:
@OneToMany(fetch= FetchType.EAGER)
    @JoinTable(name = "COUNTRY_BONUS", joinColumns =  {
        @JoinColumn(name = "COUNTRYID", referencedColumnName = "COUNTRYID")
    }, inverseJoinColumns =  {
        @JoinColumn(name = "BONUSID", referencedColumnName = "BONUSID")
    })
    private Set<Bonus> bonuses = new HashSet<Bonus>();


I just simply change the Collections and lists to Sets and HashSets.

Thanks all.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 4:37 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi,
Correct, this should work since you change the semantics from Bag to Set.

Eyal Lupu


Top
 Profile  
 
 Post subject: fetch="EAGER" not even alowed in different entitie
PostPosted: Mon Jan 14, 2008 9:50 am 
Newbie

Joined: Wed Nov 21, 2007 8:16 am
Posts: 10
Hello
I have a similar problem...

I have two different entities that i'm struggling with.

Each of these two entities have an one-to-many relation to other entities, but they are not refering to eachother.

from orm.xml

Code:
<entity class="...Unit" name="Units">
   <attributes>
      <basic name="phonenumber" />
      <one-to-many name="sensors" fetch="EAGER">
         <!-- sensors have only basic attributes -->
         <cascade>
            <cascade-persist />
            <cascade-merge />
            <cascade-remove />
         </cascade>
      </one-to-many>
      <one-to-one name="location" />
      <one-to-one name="image" />
   </attributes>
</entity>

<entity class="...Incident" name="Incident">
   <attributes>
      <basic name="unitId" />
      <basic name="sensorId" />
      <one-to-many name="receivedMessages" fetch="EAGER" />
         <!-- receivedMessages have only basic attributes -->
   </attributes>
</entity>


It seems that i can't have fetch="EAGER" on both of these entities. Why is this a problem?

We aren't talking about simultaneously fetching here

/Per-Jarle


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

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.