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]