Hi,
When I am trying to execute one-to-many relation, I am getting could not initialize a collection...
Appreciate your help on this.
Rgds,
Sri
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2
Mapping documents:
<?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>
<class name="users.User" table="USER">
<id name="id" column="USER_ID">
<generator class="native"/>
</id>
<property name="username" column="USER_NAME"/>
<set name="usergroups" lazy="true" table="USER_GROUPS">
<key column="USER_ID"/>
<one-to-many class="users.Group"/>
</set>
</class>
<class name="users.Group" table="GROUP">
<composite-id>
<key-property name="groupId" column="GROUP_ID"/>
<key-property name="appId" column="APP_ID"/>
</composite-id>
<property name="groupName" column="GROUP_KEY"/>
</class>
</hibernate-mapping
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
oracle 9i
The generated SQL (show_sql=true):
[java] Hibernate: select * from ( select user0_.USER_ID as USER1_0_, user0_.USER_NAME as USER2_0_ from USER user0_ ) where rownum <= ?
[java] User Id:1351User Name:TEST
[java] Hibernate: select usergroups0_.USER_ID as USER4_1_, usergroups0_.GROUP_ID as RESPONSI1_1_, usergroups0_.APP_ID as APP2_1_, usergroups0_.GROUP_ID as GROUPI1_1_0_, usergroups0_.APP_ID as APPT2_1_0_, usergroups0_.GROUP_KEY as GROUI3_1_0_ from GROUP usergroups0_ where usergroups0_.USER_ID=?
[java] org.hibernate.exception.SQLGrammarException: could not initialize acollection: [users.User.usergroups#1351]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1926)
[java] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
[java] at org.hibernate.persister.collection.AbstractCollectionPersiste
r.initialize(AbstractCollectionPersister.java:520)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
[java] at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
[java] at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
[java] at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
[java] at users.UserManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: ORA-00904: "USERGROUPS0_"."USER_ID": invalid identifier
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
[java] at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
[java] at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
[java] at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
[java] at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
[java] at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
[java] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
Debug level Hibernate log excerpt: