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.  [ 3 posts ] 
Author Message
 Post subject: composite-id ... unknown entity error
PostPosted: Thu Jan 04, 2007 11:18 am 
Newbie

Joined: Thu Jan 04, 2007 11:10 am
Posts: 2
Hi,

I'm using a legacy database which dosen't have a primary key. So, I created a composite key in this manner..

This is a snippet of Person.hbm.xml

<hibernate-mapping>
<class name="com.foo.Person" table="Person">
<composite-id name="PersonPK" class="com.foo.PersonPK">
<key-property name="name" column="name" type="string" />
<key-property name="id" column="id" type="string"/>
</composite-id>
<property name="status" type="string" />
<property name="service_id" type="string" />
</class>
</hibernate-mapping>

Here's a snippet of hibernate.cfg.xml

<mapping resource="com/foo/Person.hbm.xml"/>

I have a Person.java and a PersonPK.java. PersonPK is serializable, overrides equals and hashcode

I can do a select on Person (not a problem), however, when I try and load a Person by filling up a PersonPK and then doing something like this..


PersonPK pk = new PersonPK("john", "x43452");
Person person = (Person)session.load(PersonPK.class, pk);

I get this error..

org.hibernate.MappingException: Unknown entity: com.foo.PersonPK

My question is, do I need to specify PersonPK specifically somewhere? I think it maps correctly as when Hibernate starts up, I get this log output..

Mapped property: PersonPK -> name, id

what am I doing wrong?? :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 11:40 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
PersonPK pk = new PersonPK("john", "x43452");
Person person = (Person)session.load(Person.class, pk);


you wanna use the PersonPK object to load it, but you specify you're loading the Person.class.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 12:13 pm 
Newbie

Joined: Thu Jan 04, 2007 11:10 am
Posts: 2
whatta stoopid mistake to make.. my bad..

thanks!


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