-->
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: 'Unable to resolve property' saving one-to-one mapping
PostPosted: Wed Dec 06, 2006 6:24 pm 
Newbie

Joined: Wed Nov 01, 2006 6:01 pm
Posts: 2
I am getting an exception when trying to save an object that has a unidirectional one-to-one mapping using a primary key association.

The exception is:

Unable to resolve property: person ; nested exception is
org.hibernate.HibernateException: Unable to resolve property: person
org.springframwork.orm.hibernate3.HibernateSystemException: Unable to resolve property: person ; nested exception is
org.hibernate.HibernateException: Unable to resolve property: person
org.hibernarte.HibernateException: Unable to resolve property: person
at org.hibernate.tuple.entity.EntityMetamodel.getPropertyIndex(EntityMetamodel.java:357)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:286)
at org.hibernate.tuple.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3534)
at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:39)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
...

My hbm files look like this:
<class name="Person" table="person">
<id name="id" column="id" unsaved-value="null">
<generator class="native"></generator>
</id>
<property name="name">
</class>

<class name="Member" table="member">
<id name="id" column="id">
<generator class="foreign">
<param name="property"person</param>
</generator>
</id>
<property name="membershipId" column="membership_id" not-null="true" unique="true"></property>
<one-to-one name="person" cascade="all" constrained="true"/>
</class>

My java files look like this:
public class Person extends BaseObject implements Serializable {
private Long id;
private String name;

/**
* @hibernate.id column="id" generator-class="native"
*/
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

/**
* @hibernate.property
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


public class Member extends BaseObject implements Serializable {
private Long id;
private Person person = new Person();
private Long membershipId;

/**
* @hibernate.id generator-class="foreign"
* @hibernate.generator-param name="property" value="person"
*/
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

/**
* @hibernate.one-to-one cascade="all" constrained="true"
*/
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}

/**
* @hibernate.property
*/
public Long getMembershipId() {
return membershipId;
}
public void setMembershipId(Long membershipId) {
this.membershipId = membershipId;
}

My test case looks like this:

public void test1{
Member member = new Member();
member.getPerson().setName("test");
member.setMembershipId(new Long(1));
dao.saveMember(member);
}

I have tried all combinations of cascade and constrained on the one-to-one with no luck. Retrieval of person or member objects seems to work absolutely fine (using data directly inserted into the database); it's only saving objects that causes an exception.

Anyone got any ideas?
Thanks in advance

alan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 9:39 am 
Newbie

Joined: Tue Apr 25, 2006 2:08 am
Posts: 7
I too am looking for an solution for this. Does anybody have a solution?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 10:33 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Please use the tags above to make you more readable...

Did you write this in you mapping file???
Quote:
Code:
<param name="property"person</param>

Maybe that's not the only problem, but it's missing a ">" after "property"...

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Re: 'Unable to resolve property' saving one-to-one mapping
PostPosted: Tue Jan 11, 2011 4:49 pm 
Newbie

Joined: Thu Oct 28, 2010 2:27 pm
Posts: 2
I encountered this issue as well, however, with the JPA / Hibernate 3.2.4 Core annotations:

The following code allows two tables to share the same primary key and still identify a parent-child relationship. The child entity also uses the primary key as a foreign key to the parent entity.

The code in the child entity references the parent entity (CompanyBean) and has a reference to it:

Code:
   @OneToOne(optional=false, fetch=FetchType.LAZY)
   @PrimaryKeyJoinColumn(name="invlvd_co_serl")
   private CompanyBean companyBean;

    /** represents the invlvdCoSerl */
    @Id
    @GeneratedValue(generator="foreign")
    @GenericGenerator(name="foreign", strategy="foreign", parameters={
              @Parameter(name="property", value="company")}
    )
    @Column (name="invlvd_co_serl", length=32)
    private String invlvdCoSerl;


Unfortunately, the code in the annotations causes the "org.hibernate.HibernateException: Unable to resolve property: company". The @Parameter(...) annotation contains the problem: it is supposed to refer to the field in the child class whose type is the owner of the primary key, in this case, the CompanyBean. The error is the value attribute: changing company to companyBean (the correct name of the field) solves this problem.

Lesson we learned: be cautious with rename refactorings to include textual occurrences.

dan wilkin


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.