-->
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: Find by NaturalIdentifier with many-to-one
PostPosted: Wed Feb 17, 2010 9:51 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
Hello,

I have declared a <natural-id .../> that includes a <many-to-one .../> relation. I'm trying to use it in my Dao but I'm getting an org.springframework.dao.InvalidDataAccessApiUsageException: org.blah.Owner; nested exception is org.hibernate.TransientObjectException: org.blah.Owner

My test is:
Case case = new Case(new Owner("me"), ...);
assertNull(dao.findByNaturalKey(case));

The findByNaturalKey is:
NaturalIdentifier naturalId = Restrictions.naturalId();
naturalId.set("owner", case.getOwner());

It works for the other natural keys, how do I include the owner?

Thanks


Top
 Profile  
 
 Post subject: Re: Find by NaturalIdentifier with many-to-one
PostPosted: Wed Feb 17, 2010 10:21 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
I changed the dao:
naturalId.set("owner", case.getOwner().getCompanyId());

That fixed it when the owner isn't save yet.
Once it is, I'm getting a new exception:
org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of org.blah.Owner.companyId; nested exception .......
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Integer field org.blah.Company.companyId to java.lang.Integer

Now I'm really stuck...


Top
 Profile  
 
 Post subject: Re: Find by NaturalIdentifier with many-to-one
PostPosted: Wed Feb 17, 2010 10:34 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
solved it by adding an alias and including the alias in the naturalId.set("owner"...


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.