-->
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.  [ 7 posts ] 
Author Message
 Post subject: Question About nesting Many to One
PostPosted: Mon Nov 17, 2003 11:20 pm 
Newbie

Joined: Sun Nov 16, 2003 11:44 am
Posts: 7
I have nested Many to One relationships (just object references)
and they are null.


a Document object has a Employee object which has a Department object.
(many others too)

I can load it, and view it, but updates fail.
I am not certain if there is something i have to do special for nested many to one relationships.

any hints?

thanks
-fred


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 12:26 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Fred, post your mappings of your Department, Document and Employee, in particular your one-to-many relationships. As well as the code you use for loading and updating.

That'll make things a lot easier for the Hibernate team to help you.

-G


Top
 Profile  
 
 Post subject: details
PostPosted: Tue Nov 18, 2003 1:09 am 
Newbie

Joined: Sun Nov 16, 2003 11:44 am
Posts: 7
file DocumentsTO.hbm.xml---------
<hibernate-mapping>
<class name="test.documents.data.DocumentsTO" table="documents" >

<id name="documentID" type="string" unsaved-value="null">
<column name="Document_ID" sql-type="VARCHAR(36)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="documentUrl" column="Document_Url" type="string" not-null="true"/>

<many-to-one name="employeesTO" column="Employee_ID" class="test.employees.data.EmployeesTO"
not-null="true" cascade="none" outer-join="true" insert="false" update="false">
</many-to-one>
<property name="updateDate" column="Update_Date" type="date" not-null="true"/>

</class>
</hibernate-mapping>
------------
file EmployeesTO.hbm.xml--------
<hibernate-mapping>
<class name="test.employees.data.EmployeesTO" table="employees" >

<id name="employeeID" type="string" unsaved-value="null">
<column name="Employee_ID" sql-type="VARCHAR(36)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="firstName" column="First_Name" type="string" not-null="true"/>

<property name="lastName" column="Last_Name" type="string" not-null="true"/>

<property name="title" column="Title" type="string" not-null="true"/>

<property name="manager" column="Manager" type="string" not-null="true"/>

<many-to-one name="departmentsTO" column="Department" class="test.departments.data.DepartmentsTO"
not-null="true" cascade="none" outer-join="true" insert="false" update="false">
</many-to-one>
<property name="dateHire" column="Date_Hire" type="date" not-null="true"/>

</class>
</hibernate-mapping>
----------
file DepartmentsTO.hbm.xml-------
<hibernate-mapping>
<class name="test.DepartmentsTO" table="departments" >

<id name="department" type="string" unsaved-value="null">
<column name="Department" sql-type="VARCHAR(64)" not-null="true"/>
<generator class="assigned"/>
</id>

<property name="departmentHead" column="Department_Head" type="string"/>

<property name="parentDepartment" column="Parent_Department" type="string"/>

<property name="description" column="Description" type="string"/>

</class>
</hibernate-mapping>
------------

Documents (m-to-1) Enp (m-to-1) Departments.

here is an example update method (all are same)
public DepartmentsTO update(DepartmentsTO to) {
HibernateTemplate hibernateTemplate = new HibernateTemplate(this.sessionFactory);
hibernateTemplate.saveOrUpdate(to);
return to;
}

thanks,
-fred


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 1:50 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Offhand, I see you don't have any collection defined in your "one" side of the one-to-many's. i.e.

Something like this in DepartmentsTO:

Code:
<bag name="Employees" inverse="true" lazy ="true" cascade="all">
    <key column="Department" />
    <one-to-many class="test.employees.data.EmployeesTO" />
</bag>

I used bag, but you can use set, or another collection type.

This tells your parent object, that it has a 1-M relationship with your child, as well as the link you already have in your child (telling the children who the parent is).

Check out Chapter 5 in the reference document for information on various Collections, and Chapter 8 for Parent-Child relationships.

I'm not sure if there's a problem in your code, perhaps one of the Hibernate guys can check that.

Hope that helps.

-G


Top
 Profile  
 
 Post subject: few more questions
PostPosted: Tue Nov 18, 2003 9:22 am 
Newbie

Joined: Sun Nov 16, 2003 11:44 am
Posts: 7
thanks,
do i have to have the other side of the relationship setup? (i don't think i want it, if i don't need it)

-f


Top
 Profile  
 
 Post subject: question...
PostPosted: Tue Nov 18, 2003 3:28 pm 
Newbie

Joined: Sun Nov 16, 2003 11:44 am
Posts: 7
is anyone just using many to one object refernces like i am
(and don't want to use the bidirectional features)

this should be very simple. what am i missing?
thanks,
-Fred


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 6:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course. It is trivial. Just don't map your associations with

insert="false" update="false"

:)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.