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.  [ 2 posts ] 
Author Message
 Post subject: How to be notified that a child of a parent has been changed
PostPosted: Tue Dec 04, 2007 8:06 pm 
Newbie

Joined: Tue Dec 04, 2007 7:50 pm
Posts: 4
Hibernate version: 3.2.5.ga

Mapping documents: At the office...

Hi all!

I am realtive new in to Hibernate, but after researching I have not found any answer about this:

I have this classes:

Class A {
public Set Children

public Set getChildren()...
public setChildren(Set children)...
}

Class B {
public A Parent

public A getParent()...
public setParent(A parent)...
}


then in my code I have something like this:

...
A myAInstance = new A();
...
session.Save(A);
...
B myBInstance = new B();
myBInstance.setParent(A);
session.Save(B);
...


And my question is:

There is some way or workaround, using Interceptors, events etc etc to be notified/intercept that one object from B has been added to A?


The only workaround that I have found is, implement event listener (delete, update and insert) and via reflection inspect the class that is going to be affected, searching for "parents"... really nasty code.

Thanks,

PD: Sorry, my english is not good :-(

Regards from Mallorca.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 5:15 am 
Newbie

Joined: Tue Dec 04, 2007 7:50 pm
Posts: 4
Here are the maping files:

Family (Parent):


<?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 package="common.persistence">
<class
name="MaterialFamily"
table="MATERIAL_FAMILies"
lazy="false"
>
<id
name="Id"
column="MATERIAL_FAMILY_ID"
type="long"
access="wildsoftware.utils.Hibernate.DirectSetAccessor">
<generator class="increment"/>
</id>


<property
name="Name"
type="string"
column="NAME"
length="255"
not-null="true"
access="wildsoftware.utils.Hibernate.DirectSetAccessor"
/>

<!-- Limit item description to 4000 characters, Oracle. -->
<property
name="Description"
column="DESCRIPTION"
type="string"
length="4000"
not-null="false"
access="wildsoftware.utils.Hibernate.DirectSetAccessor"
/>

<set name="Materials"
inverse="false"
cascade="all"
lazy="false">
<key column="MATERIAL_FAMILY_ID"/>
<one-to-many class="Material"/>
</set>

</class>
</hibernate-mapping>



Material (Child):


<?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 package="common.persistence">
<class
name="Material"
table="MATERIAL"
lazy="false"
>
<id
name="Id"
column="MATERIAL_ID"
type="long"
access="wildsoftware.utils.Hibernate.DirectSetAccessor">
<generator class="increment"/>
</id>

<property
name="Name"
type="string"
column="NAME"
length="255"
not-null="true"
access="wildsoftware.utils.Hibernate.DirectSetAccessor"
/>

<!-- Limit item description to 4000 characters, Oracle. -->
<property
name="Description"
column="DESCRIPTION"
type="string"
length="4000"
not-null="false"
access="wildsoftware.utils.Hibernate.DirectSetAccessor"
/>

<many-to-one name="FromFamily"
class="MaterialFamily"
not-null="true"
column="FAMILY_ID"
/>

<many-to-one name="Unit"
class="UnitType"
not-null="false"
column="UNIT_TYPE_ID"
/>

</class>
</hibernate-mapping>


Thank you!


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