-->
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.  [ 5 posts ] 
Author Message
 Post subject: Failed to lazily initialize a collection
PostPosted: Thu Apr 22, 2004 2:52 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
Hi all

I am using Hib2.1.1 and MS SQL server. I got exception when Hib lazily load the collection. Is that the problem with the MS SQL JDBC driver or what?


Code:
        sf = cfg.buildSessionFactory();
        Session sess = sf.openSession();
        User user = (User) sess.load(User.class,"yang");
        Set accesses = user.getAccesss();

        System.out.println("Branch Code: " + user.getBranch());

        System.out.println
        Iterator it = accesses.iterator();  //Exception



net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:69)
at net.sf.hibernate.collection.Set.iterator(Set.java:131)
at Main.test23(Main.java:251)
at Main.test2(Main.java:197)
at Main.main(Main.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)
Caused by: net.sf.hibernate.JDBCException: could not load: [test.hibernate.Function#0201]
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:423)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1880)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
at net.sf.hibernate.type.ComponentType.resolveIdentifier(ComponentType.java:389)
at net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:145)
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:351)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:202)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:203)
... 10 more
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:228)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420)
... 26 more

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Search the forum, I think it has been answered

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is a FAQ too: http://www.hibernate.org/120.html#A6


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:23 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
michael wrote:



thanks for pointing me to FAQ and after reading it more carefully, I found that MS JDBC driver is not supported or not recommended. However, I would like to know if the latest JDBC driver SP2 driver supported?? It's released Fed 2004.


Thanks!

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Did you read the FAQ? "Simply add SelectMethod=Cursor; to your connection string. "


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