-->
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: many-to-many sets synchronizing
PostPosted: Tue May 23, 2006 3:28 pm 
Newbie

Joined: Wed Feb 08, 2006 3:57 pm
Posts: 16
Hibernate version:
3.1.3

Mapping documents:
Code:
<hibernate-mapping>
   <class name="Type" table="types">
      <id name="id" type="long" unsaved-value="null">
         <generator class="native" />
      </id>
      <set name="parents" table="TypesXTypes" inverse="true">
         <key column="child" />
         <many-to-many class="Type" column="parent"/>
      </set>
      <set name="children" table="TypesXTypes">
         <key column="parent" />
         <many-to-many class="Type" column="child" />
      </set>
   </class>
</hibernate-mapping>


Name and version of the database you are using:
MySQL 5

1. If I have nothing, but classMetadata how can I find what set is inversed (e.g. to prohibit editing the other one)

2. If I do "children.add(parent)" is there a way to synchronize the child and the parent without sending data to server and retreiving them back?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 6:48 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
I'm not quite sure what you mean in #1, but prohibiting editing is not something usually associated with the persistence layer of an application. Do you mean making one of the tables "read-only" so that updates will not occur to existing rows?

For the second question, when you are handling the persistent objects using the POJO/OO-like hibernate approach, Hibernate will be making the decisions about what needs to be sent back and forth between the database server and the client applications. It obviously has to update the database when you establish a new relationship for a persistent object or add a new persistent object. Presumably Hibernate does not send data back again from the database unless it needs to, in which case you don't really have a choice regardless of your approach. For example, there could be a property in the persistent object that corresponds to an automatically generated Id. Hibernate would have to retrieve that value so that it could be placed in the persistent object representing that new row.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 11:10 pm 
Newbie

Joined: Wed Feb 08, 2006 3:57 pm
Posts: 16
OK, I'll try to explain.
Imagine that you have Class C persisted in a database.
You also have Configuration, SessionFactory, Session, ClassMetadata etc.

The goal is to write a component which allows to edit set of instances of C:

Code:
for (int i)
{
     if (classMetadata.getPropertyTypes()[i] == IntegerType)
           ShowIntegerEditor(classMetadata.getPropertyValues()[i]);

     //blah-blah-blah

     if (classMetadata.getPropertyTypes()[i] == SetType)
           ShowSetEditor(classMetadata.getPropertyValues()[i]);

}


In case of many-to-many relationship after editing the object with SetEditor I have to update all related objects. At present I have no idea how to do it.

There is a number of workarounds of how to do this.

1. I only allow to edit one side of association (where inverse=false). Thus user have no ability to edit or view another side so I have nothing to synchronize (let's suppose application that USES the data is another one)
This is what my first question was about.
2. I set both associations to have inverse=false and after changing any set always commit the transaction. This has two bad issues:
(i) I have to send extra data there and back again (this is what my second question was about)
(ii) I cannot rollback after I made a commit.

Heh?


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.