-->
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.  [ 5 posts ] 
Author Message
 Post subject: "No persister for: ..." exception, composite-id.
PostPosted: Mon Feb 23, 2004 4:53 pm 
Newbie

Joined: Mon Feb 23, 2004 2:45 pm
Posts: 6
Just getting to know Hibernate, experiencing information overload... been going trough docs and forums without finding answer. I am sure this has been dealth with before, my apologies for not been able to find it (:

Hibernate 2.1
Oracle8

-- Tables --

ORDER
orderid PK
description

ORDER_DETAIL
orderid PK FK
userid PK
progress
assigneddate


For simplicity, assume all colums varchar.


-- order.hbm.xml --


<hibernate-mapping auto-import="false">
<class name="Order" table="ORDER">
<id name="orderid" column="orderid" type="string">
<generator class="assigned"/>
</id>
<property name="description"/>
<set name="details">
<key column="orderid" />
<one-to-many class="OrderDetail"/>
</set >
</class>
</hibernate-mapping>


-- orderdetail.hbm.xml --

<hibernate-mapping>
<class name="OrderDetail" table="ORDER_DETAIL">
<composite-id name="compID" class="OrderDetailCompId">
<key-many-to-one name="orderid" class="Order" column="orderid" />
<key-property name="userid" column="userid"/>
</composite-id>
<property name="progress"/>
<property name="assignedDate"/>
</class>
</hibernate-mapping>


I'd like to keep the question short - please take it for granted that my classes have all properties, getters and setters, OrderDetailCompId has implemented equals() and hashCode() (and implements Serializable).

I get the exception below, when running the following code - just trying to create a record in ORDER_DETAIL:

sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(new OrderDetail("order1", "user99", "", "");
tx.commit();
session.close();


[ERROR] SessionImpl - -Could not synchronize database state with session <net.sf.hibernate.MappingException: No persister for: java.lang.String>net.sf.hibernate.MappingException: No persister for: java.lang.String
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2725)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:46)
at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:154)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:399)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:466)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

I've been debugging - Hibernate is trying to persist Object with value "order1".

Now, I realize that attempting to persist a STRING is bad and indicates bad mapping or associations since STRING is not an entity.
What have I messed up - the composite key, mappings? Not enough specified?
Any help appreciated.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hm, the mapping looks allright to me ... Probably you adding a string to some collection where a persistent object should be? The log should give you more info on where this string comes from.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 9:43 pm 
Newbie

Joined: Mon Feb 23, 2004 2:45 pm
Posts: 6
Thanks, but I thing there has got to be something in the mapping though, I
enabled debug and this is what I noticed (mapping for class OrderItem):


...
[DEBUG] Binder - -Mapped property: orderid -> orderid, type: Order
...

Should have been java.lang.String.

Do you think the "many-to-one" mapping is still OK (see first post):

Code:
<key-many-to-one name="orderid" class="Order" column="orderid" />


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 7:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah, that should look like this:

Code:
<composite-id name="compID" class="OrderDetailCompId">
<key-many-to-one name="order" class="Order" column="orderid" />
<key-property name="userid" column="userid"/>
</composite-id>


and you OrderDetailCompId should look like this:

Code:
public class OrderDetailCompId {
     public Order getOrder() {...}
     public void setOrder(Order o) {...}
     public String getUserid() {...}
     public void setUserid() {...}
}


Relationships are allways made with Object references, never with storing the key of the related object in a property.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 9:27 am 
Newbie

Joined: Mon Feb 23, 2004 2:45 pm
Posts: 6
Right on :

Code:
public Order getOrder()


I had declared orderid as String in OrderDetailCompId, naturaly the getters and setters were "stringified" as well.

Changed the type to Order and it worked.

I should have posted the code, instead of that "take it for granted ..." crap.

Thanks again


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