-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy Loading Exception
PostPosted: Fri Feb 25, 2005 9:41 am 
Beginner
Beginner

Joined: Thu Feb 24, 2005 8:27 am
Posts: 21
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.7

[b]Mapping documents:


[b]Code between sessionFactory.openSession() and session.close():
Session ss = HibernateSessionFactory.currentSession();
Transaction tf= ss.beginTransaction();


tf=ss.beginTransaction();

List li = ss.find("from Sections s ");

Iterator it = li.iterator();
while (it.hasNext())
{
Sections sec = (Sections)it.next();
System.out.println("Section ID : "+sec.getSectionid());;
System.out.println("Section Nmae : "+sec.getSectionname());;


Set subli=(Set) sec.getSubjects();

Iterator subit= subli.iterator();

while (subit.hasNext())
{
Subject mysub =(Subject) subit.next();

System.out.println("Subject is : "+mysub.getSubjectname());
}


}
tf.commit();

[b]Full stack trace of any exception that occurs:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
at myclient.MyClient.main(MyClient.java:66)
Caused by: net.sf.hibernate.exception.SQLGrammarException: could not initialize collection: [mypkg.Sections.subjects#555 ]
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.collection.AbstractCollectionPersister.convert(AbstractCollectionPersister.java:728)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:291)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3303)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
... 3 more
Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'sujbectid'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:288)
... 5 more
Exception in thread "main"

[b]Name and version of the database you are using:sqlserver

Please help me out how to solve this lazy loading error.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 9:51 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Pay attention to the nested exception:
Quote:
Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'sujbectid'.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 9:54 am 
Beginner
Beginner

Joined: Thu Feb 24, 2005 8:27 am
Posts: 21
Thanks for the reply,
But actually i have specified the columen name properly in xml file. i have checked. it is not allowing me to retrieve the collection of subjects from sections. please tell me what to do.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 10:02 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Well if you don't post your mapping files we can't help


Top
 Profile  
 
 Post subject: Here are my mapping files
PostPosted: Sat Feb 26, 2005 1:36 am 
Beginner
Beginner

Joined: Thu Feb 24, 2005 8:27 am
Posts: 21
My mapping files are :

<hibernate-mapping package="mypkg">

<class name="Sections" table="Sections" >
<id name="sectionid" column="sectionID" type="java.lang.String">
<generator class="assigned"/>
</id>

<property name="sectionname" column="sectionName" type="java.lang.String" />
<set name="subjects" order-by="sujbectid desc" lazy="true" inverse="true">
<key column="sectionid"></key>
<one-to-many class="mypkg.Subject"/>
</set>
</class>

</hibernate-mapping>

<hibernate-mapping package="mypkg">

<class name="Subject" table="Subject">
<id name="subjectid" column="subjectID" type="java.lang.String">
<generator class="assigned"/>
</id>

<property name="sectionid" column="sectionID" type="java.lang.String" />
<property name="subjectname" column="subjectName" type="java.lang.String" />
</class>

</hibernate-mapping>


please help me out..why it is showing me lazy initialization exception when i try to access the method call getSubjects() from Section object....

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Here are my mapping files
PostPosted: Sat Feb 26, 2005 3:53 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
roshansalvi wrote:
<set name="subjects" order-by="sujbectid desc" lazy="true" inverse="true">


Next time just search for the offending string. By the way, why on earth are you using the JDBC-ODBC bridge?

Alin.


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