-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to load an object with a collection of values?
PostPosted: Wed Nov 05, 2003 6:25 am 
Newbie

Joined: Wed Nov 05, 2003 6:05 am
Posts: 6
Hello,

I am new to Hibernate and I don't know how to load an object with a collection of values.

Consider the following mapping:

Code:
<class name="Paper" table="papers">

                <id name="id" type="integer" unsaved-value="null">
                        <column name="id"/>
                        <generator class="sequence">
                                <param name="sequence">paper_id_seq</param>
                        </generator>
                </id>

                <!-- ... -->

                <set name="keywords" table="keywords" cascade="all">
                        <key column="paper_id"/>
                        <element column="keyword" type="string" length="100" not-null="true"/>
                </set>

</class>


When a Paper object p with a set of associated keywords (java.lang.String values) is saved using

Code:
session.save(p)


then everything goes fine. But loading a saved paper with

Code:
Paper   p = (Paper) session.load(Paper.class, id);


results in the following:

Code:
INFO: Query language substitutions: {}
Hibernate: select paper0_.id as id, paper0_.title as title, paper0_.paper_date as paper_date, paper0_.abstract as abstract, paper0_.volume as volume, paper0_.number as number, paper0_.section as section, paper0_.html_url as html_url, paper0_.pdf_url as pdf_url from papers paper0_ where paper0_.id=?
Hibernate: select keywords0_.keyword as keyword__ from keywords keywords0_ where keywords0_.paper_id=?
Paper@134b07e[id=1]
net.sf.hibernate.MappingException: No persister for: java.lang.String
        at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:420)
        at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2302)
        at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2309)
        at net.sf.hibernate.impl.SessionImpl.isSaved(SessionImpl.java:2346)
        at net.sf.hibernate.collection.PersistentCollection.identityRemove(PersistentCollection.java:593)
        at net.sf.hibernate.collection.PersistentCollection.identityRemoveAll(PersistentCollection.java:587)
        at net.sf.hibernate.collection.Set.getOrphans(Set.java:49)
        at net.sf.hibernate.impl.SessionImpl.getOrphans(SessionImpl.java:2874)
        at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:305)
        at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
        at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2285)
        at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2015)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2004)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)


Any idea what is wrong? Any help appreciated.

Best regards,

Peter[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 6:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What happens if you remove cascade="all"?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 6:43 am 
Newbie

Joined: Wed Nov 05, 2003 6:05 am
Posts: 6
Removing cascade from the mappig solved the problem.

Thank you very much!

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 7:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I'm guessing that what you actually had was cascade="all-delete-orphan", since getOrphans() was called during flush().


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