-->
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.  [ 2 posts ] 
Author Message
 Post subject: HibernateException: null index column for collection: ...
PostPosted: Thu May 25, 2006 5:15 am 
Newbie

Joined: Sun May 01, 2005 12:04 pm
Posts: 6
Location: Munich, Germany
Hibernate version:
3.1

Mapping documents:
I am mapping User and Album -> 1 user may have * Albums
I am using a list interface, so I am using the list element and an list-index in my mapping. The pos column is created in the schema.

Here is the user mapping:

<hibernate-mapping
package="de.pixxi.om">

<class name="User" table="User">

<id name="id" type="string" unsaved-value="null" >
<column name="userId" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="username"/>
<property name="password"/>
<property name="verification"/>
<property name="sex"/>
<property name="firstname"/>
<property name="lastname"/>
<property name="email"/>
<property name="birthday" type="date"/>
<property name="newsletterrequested"/>

<list name="albums" table="Album" cascade="all-delete-orphan" outer-join="true" inverse="true">
<key column="userId"/>
<list-index column="pos" base="1"/>
<one-to-many class="Album" />
</list>

</class>

</hibernate-mapping>

And here is the Album (Album has Images, but this is irrelevant)

<hibernate-mapping
package="de.pixxi.om">

<class name="Album" table="Album">

<id name="id" type="string" unsaved-value="null" >
<column name="albumId" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>


<property name="name"/>

<list name="images" table="Image" cascade="all-delete-orphan" outer-join="true" inverse="true">
<key column="albumId"/>
<list-index column="pos" base="1"/>
<one-to-many class="Image" />
</list>

<many-to-one
name="user"
class="User"
column="userId"
not-null="true"
/>

</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Session session = this.getSession();
Transaction tx = session.beginTransaction();

User user;
Criteria crit = session.createCriteria(User.class);
crit.setFetchMode("albums", FetchMode.JOIN);
crit.add(Expression.eq("username", username));
crit.setMaxResults(1);
List userList = crit.list();
if (userList != null)
log.debug("Anzahl user gefunden: " + userList.size());
if (userList == null || userList.size() < 1) {
log.warn("User not found!");
return null;
} else
user = (User) userList.get(0);

tx.commit();
session.close();

Full stack trace of any exception that occurs:

Note: it is happening in a JSF web app. After creating a user and adding an album, the user is reloaded. While loading, the error occurs because <b>the pos column</b> does not contain an index. it is simply null.... but I don't get why hibernate does not fill out the pos column...

Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{verificationBean.verify}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
... 23 more
Caused by: org.hibernate.HibernateException: null index column for collection: de.pixxi.om.User.albums
at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:652)
at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:358)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:994)
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.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1552)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at de.pixxi.biz.AlbumDelegateImpl.getUser(Unknown Source)
at de.pixxi.model.VerificationBean.verify(Unknown Source)
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:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
... 24 more

Name and version of the database you are using:
MySQL 5


The generated SQL (show_sql=true):

sorry, don't have it. But the error reason is that the album list cannot be ordered, as the pos column in the Album table is null.

One thing: I am using a typed List<Album> in User. Could this be the reason?

Any help is highly appreciated... thanx a lot!

Cheers
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 1:23 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The first thing to do is to set the pos columns to be NOT NULL. I don't know why list-index doesn't take a not-null attribute, perhaps the schematool always puts NOT NULL on list-index columns. Either way, once that's a not-null column, you'll get an exception any time a row with a null list-index is added, and that'll help you track down the cause of the problem.

_________________
Code tags are your friend. Know them and use them.


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