-->
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: Help needed in One to one mapping
PostPosted: Sun May 13, 2007 2:13 pm 
Newbie

Joined: Fri May 04, 2007 1:48 pm
Posts: 7
Hi,

I am trying to do a sample on One to One mapping. My sample consists of a Employee and a Parking space.

Each employee will have a parking space. It is a uni directional relationship.

Following is my Employee code.

package com.sample.employee;

public class Employee
{
private long employeeId;
private String employeeName;
private long salary;
private ParkingSpace parkingSpace;

public void setEmployeeId(long employeeId)
{
this.employeeId = employeeId;
}

public long getEmployeeId()
{
return this.employeeId;
}

public void setEmployeeName(String employeeName)
{
this.employeeName = employeeName;
}

public String getEmployeeName()
{
return this.employeeName;
}

public void setSalary(long salary)
{
this.salary = salary;
}

public long getSalary()
{
return this.salary;
}

public void setParkingSpace(ParkingSpace parkingSpace)
{
this.parkingSpace = parkingSpace;
}

public ParkingSpace getParkingSpace()
{
return this.parkingSpace;
}

}

Following is my parking space code.

package com.sample.employee;

public class ParkingSpace
{
private long parkingSpaceId;
private String lotName;

public void setParkingSpaceId(long parkingSpaceId)
{
this.parkingSpaceId = parkingSpaceId;
}

public long getParkingSpaceId()
{
return this.parkingSpaceId;
}

public void setLotName(String lotName)
{
this.lotName = lotName;
}

public String getLotName()
{
return this.lotName;
}
}

Following is my Employee HBM file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.sample.employee.Employee" table="EMPLOYEE_DETAILS">
<id name="employeeId" type="long" column="EMPLOYEE_ID" >
<generator class="assigned"/>
</id>

<property name="employeeName">
<column name="EMPLOYEE_NAME" />
</property>
<property name="salary">
<column name="SALARY"/>
</property>

<one-to-one name="parkingSpace" class = "com.sample.employee.ParkingSpace" />

</class>
</hibernate-mapping>


Following is my Parking space HBM file.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.sample.employee.ParkingSpace" table="PARKING_SPACE">
<id name="parkingSpaceId" type="long" column="PARKING_SPACE_ID" >
<generator class="assigned"/>
</id>

<property name="lotName">
<column name="LOT_NAME" />
</property>
</class>
</hibernate-mapping>


When i try to persist the employee details does not have the parking space id in the table.

What am i missing here.

Any help would be helpful.

Thanks in Advance.

Balaji.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 11:35 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
I couldn't understand what you want to ask.

When i try to persist the employee details does not have the parking space id in the table.

You are getting some Exception .

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 7:27 am 
Newbie

Joined: Fri May 04, 2007 1:48 pm
Posts: 7
I want a one to one mapping with employee and parking space. i first create a parking space and then create a employee by passing the parking space object to it. i set the parking space by

emp.setParkingSpace(ps);

where ps is the parking space object.

i hoped that the id of parking space will be stored in the employee table. But it was not the case. i had all the other details of the employee excpet the parking space id.

When i used many to one mapping instead of one to one mapping like this

<many-to-one name="parkingSpace" class="com.sample.employee.ParkingSapce" column="PARKING_SPACE_ID" unique="true" />

i was able to get the parking space id in the employee table, but the problem is, the same parking space id was persisted with more than one employee, which is not what i want.

I hope i have made myself clear.

Any help in this issue would be much appreciated.

Thanks in advance.

Balaji


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.