-->
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: parent/child one-to-many doubt? please clear.
PostPosted: Wed Sep 03, 2008 4:43 am 
Newbie

Joined: Wed Aug 01, 2007 4:00 am
Posts: 8
Hello Friends,

I have got a parent/child one-to-many mapping 'Employee to ServiceEntry'. My domains and mapping files has been listed
below.

I just want to know whether the adding and deleting part of
child given below in ServiceEntryService.java is correct?

ServiceEntry.java
--------------------
public class ServiceEntry
{
private Long id;
.......
private Employee attendedBy;


geters......
seters......

public Employee getAttendedBy()
{
return attendedBy;
}

public void setAttendedBy(Employee attendedBy)
{
this.attendedBy = (Employee)attendedBy;
}

public Employee getCurrentlyAssignedTo()
{
return currentlyAssignedTo;
}
}


Employee.java
-----------------
public class Employee
{
private Integer id;
.......
private Set serviceCallAttendedList = new HashSet();

geters......
seters......

public Set getServiceCallAttendedList()
{
return serviceCallAttendedList;
}

public void setServiceCallAttendedList(Set serviceCallAttendedList)
{
this.serviceCallAttendedList = serviceCallAttendedList;
}

public void addServiceCallAttendedEntry(ServiceEntry aServiceEntry)
{
if ( serviceCallAttendedList == null )
{
serviceCallAttendedList = new HashSet();
}
serviceCallAttendedList.add(aServiceEntry);
}

public void removeServiceCallAttendedEntry(ServiceEntry aServiceEntry)
{
serviceCallAttendedList.remove(aServiceEntry);
}
}


ServiceEntry.hbm.xml
--------------------------
..........
<hibernate-mapping>
<class name="com.sample.domain.ServiceEntry" table="service_entry">
<id name="id" column="id">
<generator class="native" />
</id>
...........
...........
<many-to-one name="attendedBy" class="com.sample.domain.Employee" column="attendedBy" not-null="true" />
</class>
</hibernate-mapping>


Employee.hbm.xml
----------------------
..........

<hibernate-mapping>
<class name="com.sample.domain.Employee" table="employee">
<id name="id" type="integer" column="id">
<generator class="native" />
</id>
...........
...........
</set>
<set name="serviceCallAttendedList" inverse="true" lazy="true" table="service_entry">
<key column="attendedBy" not-null="true" />
<one-to-many class="com.sample.domain.ServiceEntry" />
</class>
</hibernate-mapping>

ServiceEntryService.java
-----------------------------
public class ServiceEntryService implements IServiceEntryService
{
..........
..........
@Transactional(propagation = Propagation.REQUIRED)
public void saveServiceEntry(ServiceEntry serviceEntry, Integer employeeId)
{
try
{
Employee employeeAttended = employeeDAO.loadEmployee(employeeId);
serviceEntry.setAttendedBy(employeeAttended);
employeeAttended.addServiceCallAttendedEntry(serviceEntry);
serviceEntryDAO.saveServiceEntry(serviceEntry);
}
catch (Exception exception)
{
throw new BusinessEntityException(exception);
}
}

@Transactional(propagation = Propagation.REQUIRED)
public void deleteServiceEntry(ServiceEntry serviceEntry)
{
serviceEntry.getAttendedBy().getServiceAssignedList().remove(serviceEntry);
serviceEntryDAO.deleteServiceEntry(serviceEntry);
}
}

Thank you.

Sudheer


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.