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: fetching data through collection
PostPosted: Tue Oct 09, 2007 9:33 am 
Newbie

Joined: Tue Oct 09, 2007 9:19 am
Posts: 3
hi

I am stuck with a problem on retrieving datas through Collection and am
unable to solve it .






Configuration conf=new Configuration().addResource("Mapping/person.hbm.xml");
SessionFactory sf=conf.buildSessionFactory();
Session sess=sf.openSession();

Transaction tr=sess.beginTransaction();
Person p1=(Person)sess.get(Person.class,new Long(4));

Set s=p1.getAddress()//this method is supposed to return collection of address.
tr.commit();
sess.flush();
sess.close();



Person.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate MAPPING DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="Mapping">
<class name="Person" table="person" >
<id name="id" column="personId" unsaved-value="0" type="long">
<generator class="increment"/>
</id>
<set name="address" cascade="all" lazy="false" table="address" >
<key column="personId"
not-null="true"/>
<one-to-many class="Address" />
</set>
</class>
<class name="Address">
<id name="id" column="addressId" unsaved-value="0">
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>

When i run this code ,i get runtime exception as shown below

org.hibernate.exception.GenericJDBCException: could not initialize a collection: [Mapping.Person.address#4]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1926)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1627)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:827)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:806)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
at Mapping.exampleprogram.main(exampleprogram.java:38)
Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataDouble(JdbcOdbc.java:3612)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataDouble(JdbcOdbcResultSet.java:5438)
at sun.jdbc.odbc.JdbcOdbcResultSet.getLong(JdbcOdbcResultSet.java:617)
at sun.jdbc.odbc.JdbcOdbcResultSet.getLong(JdbcOdbcResultSet.java:635)
at org.hibernate.type.LongType.get(LongType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.persister.collection.AbstractCollectionPersister.readKey(AbstractCollectionPersister.java:676)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:962)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
... 20 more

could not initialize a collection: [Mapping.Person.address#4]



Please help to solve me this problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 10:14 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I am not well versed with SQL-Server but the nested SQLException in your trace is something like this

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index

and this is what I found while looking for details

This exception is usually thrown when retrieving a LONGVARCHAR or LONGVARBINARY column using the getXXXStream() method (column size > DefMaxFieldSize of idss.ini). This exception can be avoided by re-ordering your SELECT statement so that the long column is place at the end of the select list.

In the two examples below, assume that picture is the only LONGVARBINARY type column. Then the first SELECT statement can cause this exception, while the second one works fine:

SELECT name, picture, address FROM employee
SELECT name, address, picture FROM employee

If there are two or more long columns in the same select list, place all of them at the end of the select list and make sure that your JDBC program retrieve them in the same order as they appear in the select list.


Hope that gives you some pointer to resolve the issue.


Top
 Profile  
 
 Post subject: fetching data through collection
PostPosted: Wed Oct 10, 2007 3:10 am 
Newbie

Joined: Tue Oct 09, 2007 9:19 am
Posts: 3
Hi

Thnxs for repying The main problem which i m getting is "could not initialize the collection ".I do not have any column in table which is long .

Hope u can throw light on this problem.

sethrohit1977 wrote:
I am not well versed with SQL-Server but the nested SQLException in your trace is something like this

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index

and this is what I found while looking for details

This exception is usually thrown when retrieving a LONGVARCHAR or LONGVARBINARY column using the getXXXStream() method (column size > DefMaxFieldSize of idss.ini). This exception can be avoided by re-ordering your SELECT statement so that the long column is place at the end of the select list.

In the two examples below, assume that picture is the only LONGVARBINARY type column. Then the first SELECT statement can cause this exception, while the second one works fine:

SELECT name, picture, address FROM employee
SELECT name, address, picture FROM employee

If there are two or more long columns in the same select list, place all of them at the end of the select list and make sure that your JDBC program retrieve them in the same order as they appear in the select list.


Hope that gives you some pointer to resolve the issue.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 3:55 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Again the problem "could not initialize the collection" is being surfaced because of a nested "
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index" exception.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 4:02 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
BTW you can see this discussion for some pointers

http://forums.hibernate.org/viewtopic.p ... 7ac29b6471


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.