-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with one to one mapping
PostPosted: Mon Apr 09, 2012 1:44 pm 
Newbie

Joined: Tue Mar 27, 2012 9:19 am
Posts: 5
I'm facing a problem in hibernate one to one mapping. Googled a lot but unable to solve.

Here is database

<a href="http://www.freeimagehosting.net/55avs"><img src="http://www.freeimagehosting.net/t/55avs.jpg"></a>

Following are my model classes.

public class User {

private int userId;
private String userName;
private Address address;

public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}

public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}

}

and

public class Address {

private int addrId;
private String addr;

public int getAddrId() {
return addrId;
}
public void setAddrId(int addrId) {
this.addrId = addrId;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}

}

user.hbm.xml is as following:

<class name="User" table="users" schema="dbo" catalog="test">
<id name="userId" type="int" column="userId" >
<generator class="assigned"/>
</id>

<property name="userName">
<column name="userName" />
</property>

<one-to-one name="address" property-ref="addrId" class="Address" cascade="all" />

</class>

address.hbm.xml is as below,

<class name="ammar.Address" table="Address" schema="dbo" catalog="test">

<id name="addrId" type="int" column="AddrID" >
<generator class="assigned"/>
</id>

<property name="addr">
<column name="Addr" />
</property>

</class>

On running, following exception occurs:

Exception in thread "main" org.hibernate.HibernateException: Unable to resolve property: addrId

Runs fine without mapping. But can't retrieve records when mapping applied.

The query printed by hibernate runs perfectly fine in DB.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.