-->
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: composite-element and MappingException: no persister for
PostPosted: Wed Apr 14, 2004 10:21 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Hello,

I am using Hibernate 2.1.2, and am running into an odd problem. I have a class that has a Set of objects defined as composite-elements. There is no mapping document for the element, but there is a mapping file for the holding class. That snippet is:

<set
name="activities"
table="BUSINESS_ACTIVITIES"
lazy="true"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted">

<key column="business_id"/>

<composite-element class="com.hic.eboss.Activity">

<property
name="type"
type="com.hic.eboss.ActivityType"
update="true"
insert="true"
column="type"/>

<property
name="started"
type="java.util.Date"
update="true"
insert="true"
column="started" />

</composite-element>
</set>

When I add some Activities into this object and try to save it, the correct SQL statements are generated, but an exception is thrown by hibernate:

net.sf.hibernate.MappingException: No persister for: com.hic.eboss.Activity
net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
net.sf.hibernate.impl.SessionImpl.isSaved(SessionImpl.java:2700)

Some of the debug log follows:

[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] Inserting rows of collection: [com.hic.eboss.Business.activities#402801e6fbebdad900fbebdda5c90005]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] insert into BUSINESS_ACTIVITIES (business_id, type, started) values (?, ?, ?)
Hibernate: insert into BUSINESS_ACTIVITIES (business_id, type, started) values (?, ?, ?)
.......
[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] done inserting rows: 3 inserted
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.impl.SessionImpl] post flush
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] commit
[DEBUG,net.sf.hibernate.impl.SessionImpl] flushing session
.......
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.eboss.Business.activities
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] rollback
[DEBUG,net.sf.hibernate.impl.SessionImpl] transaction completion
[DEBUG,net.sf.hibernate.impl.SessionImpl] flushing session

It's very odd. The schemaexport tool creates the right DDL given the above mapping file, and Hibernate seems to be making the write SQL. Still, an exception is thrown.

Any ideas or tips?

Thanks very much!
Seth


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 11:03 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
After reading some of the document (great job, btw!), I thought I had a lead on the solution to this problem.

In Chapter 7, it states that if a Set has composite-elements, then none of the properties can be null. I am leaving one property null, so I thought that might be it. I changed the java.util.Set over to java.util.List, and then changed the hibernate collection to a bag. (I didn't choose list because there wasn't anything to order by)

Unfortunately, this does not help. I still receive the "No persister for" error.

Thanks,
Seth


Top
 Profile  
 
 Post subject: Fixed
PostPosted: Thu Apr 15, 2004 8:14 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
I found out the problem. I had to remove the cascade="all-delete-orphan" attribute from the <set>.

I don't know if it's because I set cascade to something, or the value of all-delete-orphan was causing the problem.

Moral of the story, don't use cascade="all-delete-orphan" when you have a collection (set, bag, or list) of composite-elements.

Wonder how I get this into the documentation?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 8:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I think that this is expected, as a component/composite element has "pass by value" semantics, so an "orphan" can actually never exist, as a value type is always bound to the lifecycle of its containing/parent entity.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 8:21 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Yeah, it makes sense. The error message, though, makes debugging this problem very difficult.

Still, where would I send a patch to the documentation? This would be helpful information for others.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 8:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Post a JIRA issue, you don't have to provide a full patch for documentation (it has been updated for the next release anyway).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.