-->
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.  [ 11 posts ] 
Author Message
 Post subject: Foreign key of a set element is NULL
PostPosted: Fri Oct 21, 2005 5:12 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 10:47 am
Posts: 20
Location: Basel
Hello everyone !
I'm a bit new to hibernate and have a problem for mapping a list. Here is some description :

Problem description :
When I try to save an object (WordEN) that contains a Set with only one element (WordFormEN) inside it, the foreign key linking this element with the container (WordEN) is NULL, what brings up a "integrity constraint violation message from server".
In our project we use an object factory (BOMClassManager) that generates the POJO that will be used afterwards (WordEN, WordFormEN,...). I guess the problem comes from here but I'm not sure and most of all, I don't know how to solve that problem. I must also say that in our project we also define our own Interceptor. I'm not quite sure whether this is a good strategy or not.
But enough presentation here are the technical details ;)

Hibernate version : 3.0.5

Mapping documents :

WordEN
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eserve">
   <class name="WordEN" table="WORDS_EN">
      <id name="key" column="id">
         <generator class="assigned"/>
      </id>
      <property name="noPartWordMatch" column="no_part_word_match"/>
      <property name="title"/>
      <set name="wordForms" inverse="true" table="WORD_FORMS_EN" cascade="all-delete-orphan">
         <key column="WORD_KEY"/>
         <one-to-many class="WordFormEN"/>
      </set>
   </class>
</hibernate-mapping>

WordFormEN
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eserve">
   <class name="WordFormEN" table="WORD_FORMS_EN">
      <id name="id">
         <generator class="assigned"/>
      </id>
      <property name="form"/>
      <many-to-one name="word_key" class="WordEN"/>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close() :
Code:
// Get the object factory from where it is initialized
BOMClassManager factory = bomRepository.getBOMClassManager();

// Initialize the instance of the container and the content.
InstanceIntf instanceWord = factory.getClassIntf("WordEN").createInstance();
InstanceIntf instanceWordForm = factory.getClassIntf("WordFormEN").createInstance();
     
try
{
   // Initialize the common attributes of the both classes
   instanceWordForm.setAttrValue("form","some form");
   instanceWord.setAttrValue("title","word");

   // Initialize the list and add the WordForm to the Word
   Set words = (Set)instanceWord.getAttrValue("wordForms");
   words.add(instanceWordForm);
   instanceWord.setAttrValue("wordForms",words);

   // Persist the entire Word in the database
   Session s = this.hibernateRepository.currentSession();
   Transaction tx = s.beginTransaction();
   s.save(instanceWord);
   tx.commit();
}
catch (Exception e)
{
   e.printStackTrace();
}


Full stack trace of any exception that occurs :
Code:
DEBUG - Could not execute JDBC batch update [insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)]
java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Column 'word_key' cannot be null"
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at eserve.components.hibernate.HibernateComponent.doStart(HibernateComponent.java:83)
   at eserve.framework.stdimpl.component.StdAbstractComponent.start(StdAbstractComponent.java:190)
   at eserve.framework.stdimpl.component.StdApplicationComponent$StartVisitor.visit(StdApplicationComponent.java:563)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:365)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:372)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:360)
   at eserve.framework.stdimpl.component.StdApplicationComponent._start(StdApplicationComponent.java:274)
   at eserve.framework.stdimpl.component.StdApplicationComponent.start(StdApplicationComponent.java:312)
   at eserve.plugin.EservePlugin$EserveStartThread.run(EservePlugin.java:414)
WARN  - SQL Error: 1048, SQLState: 23000
ERROR - Duplicate key or integrity constraint violation message from server: "Column 'word_key' cannot be null"
ERROR - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at eserve.components.hibernate.HibernateComponent.doStart(HibernateComponent.java:83)
   at eserve.framework.stdimpl.component.StdAbstractComponent.start(StdAbstractComponent.java:190)
   at eserve.framework.stdimpl.component.StdApplicationComponent$StartVisitor.visit(StdApplicationComponent.java:563)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:365)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:372)
   at eserve.framework.stdimpl.component.StdApplicationComponent.visit(StdApplicationComponent.java:360)
   at eserve.framework.stdimpl.component.StdApplicationComponent._start(StdApplicationComponent.java:274)
   at eserve.framework.stdimpl.component.StdApplicationComponent.start(StdApplicationComponent.java:312)
   at eserve.plugin.EservePlugin$EserveStartThread.run(EservePlugin.java:414)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Column 'word_key' cannot be null"
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
   ... 16 more


Name and version of the database you are using : MySQL version : 5.0.12-beta-nt-max

The generated SQL (show_sql=true) :
Code:
Hibernate: select wordformen_.id, wordformen_.form as form38_, wordformen_.word_key as word3_38_ from WORD_FORMS_EN wordformen_ where wordformen_.id=?
Hibernate: insert into WORDS_EN (no_part_word_match, title, id) values (?, ?, ?)
Hibernate: insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)

Debug level Hibernate log excerpt :
Code:
DEBUG - Static SQL for entity: eserve.WordFormEN
DEBUG -  Version select: select id from WORD_FORMS_EN where id =?
DEBUG -  Snapshot select: select wordformen_.id, wordformen_.form as form38_, wordformen_.word_key as word3_38_ from WORD_FORMS_EN wordformen_ where wordformen_.id=?
DEBUG -  Insert 0: insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)
DEBUG -  Update 0: update WORD_FORMS_EN set form=?, word_key=? where id=?
DEBUG -  Delete 0: delete from WORD_FORMS_EN where id=?
DEBUG - Static SQL for entity: eserve.WordEN
DEBUG -  Version select: select id from WORDS_EN where id =?
DEBUG -  Snapshot select: select worden_.id, worden_.no_part_word_match as no2_36_, worden_.title as title36_ from WORDS_EN worden_ where worden_.id=?
DEBUG -  Insert 0: insert into WORDS_EN (no_part_word_match, title, id) values (?, ?, ?)
DEBUG -  Update 0: update WORDS_EN set no_part_word_match=?, title=? where id=?
DEBUG -  Delete 0: delete from WORDS_EN where id=?
DEBUG - Static SQL for collection: eserve.WordEN.wordForms
DEBUG -  Row insert: update WORD_FORMS_EN set WORD_KEY=? where id=?
DEBUG -  Row delete: update WORD_FORMS_EN set WORD_KEY=null where WORD_KEY=? and id=?
DEBUG -  One-shot delete: update WORD_FORMS_EN set WORD_KEY=null where WORD_KEY=?
DEBUG - Static select for entity eserve.WordFormEN: select wordformen0_.id as id0_, wordformen0_.form as form38_0_, wordformen0_.word_key as word3_38_0_ from WORD_FORMS_EN wordformen0_ where wordformen0_.id=?
DEBUG - Static select for entity eserve.WordFormEN: select wordformen0_.id as id0_, wordformen0_.form as form38_0_, wordformen0_.word_key as word3_38_0_ from WORD_FORMS_EN wordformen0_ where wordformen0_.id=?
DEBUG - Static select for entity eserve.WordFormEN: select wordformen0_.id as id0_, wordformen0_.form as form38_0_, wordformen0_.word_key as word3_38_0_ from WORD_FORMS_EN wordformen0_ where wordformen0_.id=? for update
DEBUG - Static select for entity eserve.WordFormEN: select wordformen0_.id as id0_, wordformen0_.form as form38_0_, wordformen0_.word_key as word3_38_0_ from WORD_FORMS_EN wordformen0_ where wordformen0_.id=? for update
DEBUG - Static select for entity eserve.WordEN: select worden0_.id as id0_, worden0_.no_part_word_match as no2_36_0_, worden0_.title as title36_0_ from WORDS_EN worden0_ where worden0_.id=?
DEBUG - Static select for entity eserve.WordEN: select worden0_.id as id0_, worden0_.no_part_word_match as no2_36_0_, worden0_.title as title36_0_ from WORDS_EN worden0_ where worden0_.id=?
DEBUG - Static select for entity eserve.WordEN: select worden0_.id as id0_, worden0_.no_part_word_match as no2_36_0_, worden0_.title as title36_0_ from WORDS_EN worden0_ where worden0_.id=? for update
DEBUG - Static select for entity eserve.WordEN: select worden0_.id as id0_, worden0_.no_part_word_match as no2_36_0_, worden0_.title as title36_0_ from WORDS_EN worden0_ where worden0_.id=? for update
DEBUG - Static select for one-to-many eserve.WordEN.wordForms: select wordforms0_.WORD_KEY as WORD4_1_, wordforms0_.id as id1_, wordforms0_.id as id0_, wordforms0_.form as form38_0_, wordforms0_.word_key as word3_38_0_ from WORD_FORMS_EN wordforms0_ where wordforms0_.WORD_KEY=?
DEBUG - initializing class SessionFactoryObjectFactory
DEBUG - registered: 2c9082d20712670d010712671f680000 (unnamed)
INFO  - Not binding factory to JNDI, no JNDI name configured
DEBUG - instantiated session factory
INFO  - Checking 0 named queries
DEBUG - opened session at timestamp: 4628009562173440
DEBUG - closing session
DEBUG - opened session at timestamp: 4628009562685440
DEBUG - begin
DEBUG - opening JDBC connection
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - current autocommit status: false
DEBUG - saving transient instance
DEBUG - generated identifier: 00400276217010000000f9a04b6ea0da, using strategy: org.hibernate.id.Assigned
DEBUG - saving [eserve.WordEN#00400276217010000000f9a04b6ea0da]
DEBUG - processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - done processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - Wrapped collection in role: eserve.WordEN.wordForms
DEBUG - processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - cascade ACTION_SAVE_UPDATE for collection: eserve.WordEN.wordForms
DEBUG - cascading to saveOrUpdate: eserve.WordFormEN
DEBUG - id unsaved-value strategy UNDEFINED
DEBUG - Getting current persistent state for: [eserve.WordFormEN#10400276217010000000f9a04b6ea0da]
DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - select wordformen_.id, wordformen_.form as form38_, wordformen_.word_key as word3_38_ from WORD_FORMS_EN wordformen_ where wordformen_.id=?
Hibernate: select wordformen_.id, wordformen_.form as form38_, wordformen_.word_key as word3_38_ from WORD_FORMS_EN wordformen_ where wordformen_.id=?
DEBUG - preparing statement
DEBUG - running Session.finalize()
DEBUG - binding '10400276217010000000f9a04b6ea0da' to parameter: 1
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - transient instance of: eserve.WordFormEN
DEBUG - saving transient instance
DEBUG - generated identifier: 10400276217010000000f9a04b6ea0da, using strategy: org.hibernate.id.Assigned
DEBUG - saving [eserve.WordFormEN#10400276217010000000f9a04b6ea0da]
DEBUG - done cascade ACTION_SAVE_UPDATE for collection: eserve.WordEN.wordForms
DEBUG - deleting orphans for collection: eserve.WordEN.wordForms
DEBUG - done deleting orphans for collection: eserve.WordEN.wordForms
DEBUG - done processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - commit
DEBUG - automatically flushing session
DEBUG - flushing session
DEBUG - processing flush-time cascades
DEBUG - processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - cascade ACTION_SAVE_UPDATE for collection: eserve.WordEN.wordForms
DEBUG - cascading to saveOrUpdate: eserve.WordFormEN
DEBUG - persistent instance of: eserve.WordFormEN
DEBUG - ignoring persistent instance
DEBUG - object already associated with session: [eserve.WordFormEN#10400276217010000000f9a04b6ea0da]
DEBUG - done cascade ACTION_SAVE_UPDATE for collection: eserve.WordEN.wordForms
DEBUG - deleting orphans for collection: eserve.WordEN.wordForms
DEBUG - done deleting orphans for collection: eserve.WordEN.wordForms
DEBUG - done processing cascade ACTION_SAVE_UPDATE for: eserve.WordEN
DEBUG - dirty checking collections
DEBUG - Flushing entities and processing referenced collections
DEBUG - Collection found: [eserve.WordEN.wordForms#00400276217010000000f9a04b6ea0da], was: [<unreferenced>] (initialized)
DEBUG - Processing unreferenced collections
DEBUG - Scheduling collection removes/(re)creates/updates
DEBUG - Flushed: 2 insertions, 0 updates, 0 deletions to 2 objects
DEBUG - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
DEBUG - listing entities:
DEBUG - eserve.WordEN{key=00400276217010000000f9a04b6ea0da, title=word, wordForms=[eserve.WordFormEN#10400276217010000000f9a04b6ea0da], noPartWordMatch=false}
DEBUG - eserve.WordFormEN{form=some form, word_key=null, id=10400276217010000000f9a04b6ea0da}
DEBUG - executing flush
DEBUG - Inserting entity: [eserve.WordEN#00400276217010000000f9a04b6ea0da]
DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - insert into WORDS_EN (no_part_word_match, title, id) values (?, ?, ?)
Hibernate: insert into WORDS_EN (no_part_word_match, title, id) values (?, ?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [eserve.WordEN#00400276217010000000f9a04b6ea0da]
DEBUG - binding 'false' to parameter: 1
DEBUG - binding 'word' to parameter: 2
DEBUG - binding '00400276217010000000f9a04b6ea0da' to parameter: 3
DEBUG - Adding to batch
DEBUG - Inserting entity: [eserve.WordFormEN#10400276217010000000f9a04b6ea0da]
DEBUG - Executing batch size: 1
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)
Hibernate: insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [eserve.WordFormEN#10400276217010000000f9a04b6ea0da]
DEBUG - binding 'some form' to parameter: 1
DEBUG - binding null to parameter: 2
DEBUG - binding '10400276217010000000f9a04b6ea0da' to parameter: 3
DEBUG - Adding to batch
DEBUG - Executing batch size: 1
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - Could not execute JDBC batch update [insert into WORD_FORMS_EN (form, word_key, id) values (?, ?, ?)]

And then comes the exception and the stack trace.
I have been strugling with this problem for more than a week now, I have read the documentation and searched the wiki, but wherever I look, I can't find an answer.

Thank you for your patience and in advance for your reply.
Regards,
Joel.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 8:59 am 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
in your code you are adding the word form to the set of the word forms of the word but you are not doing the setting of the word on the word form

so your code should be something like this:
[code]
instanceWordForm.setAttrValue("form","some form");
instanceWord.setAttrValue("title","word");

// Initialize the list and add the WordForm to the Word
Set words = (Set)instanceWord.getAttrValue("wordForms");
words.add(instanceWordForm);

// ***** extra line here *******
instanceWordForm.setAttr("word_key", instanceWord);

instanceWord.setAttrValue("wordForms",words);

// Persist the entire Word in the database
Session s = this.hibernateRepository.currentSession();
Transaction tx = s.beginTransaction();
s.save(instanceWord);
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 9:09 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 10:47 am
Posts: 20
Location: Basel
ashneyde wrote:
Code:
// ***** extra line here *******
instanceWordForm.setAttr("word_key", instanceWord);

Uh... :/
Don't Hibernate do that automatically ?...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 9:14 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
joel wrote:
ashneyde wrote:
Code:
// ***** extra line here *******
instanceWordForm.setAttr("word_key", instanceWord);

Uh... :/
Don't Hibernate do that automatically ?...


This isn't a hibernate issue. It's an Object issue. You didn't set the property on the child class.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 9:14 am 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
Unless, I was hibernating for too long ... and they implemented it in 3.0.5 and I just missed it. But that is what you have to do for sure in 3.1rc2, so I am pretty sure you have to do it in 3.0.5.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 9:19 am 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
pksiv wrote:
This isn't a hibernate issue. It's an Object issue. You didn't set the property on the child class.


well that is arguable whose issue that is. The second stmt is redundant and could be avoided since hibernate knows that the association is two ways. But of course you can argue that hibernate does not want to do the magic tricks for you and wants you to be aware of what you are doing, but that sometimes defeats common sense :-)

Either way is fine as long as hibernators are clear on that and I think they are. They are even suggesting to create an auxilary method like add(child) and do the management there.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 10:03 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 10:47 am
Posts: 20
Location: Basel
ashneyde wrote:
Unless, I was hibernating for too long...

He he... Nice pun ;)

ashneyde wrote:
The second stmt is redundant and could be avoided since hibernate knows that the association is two ways.

Exactly ! Hibernate knows everything about the relationship, can't this information be filled automatically in Nullability.checkNullability() or, may be better, in Persistent*.add() ?
The point is that the classes WordEN and WordFormEN (and the others...) are generated (the java source code is generated and then compiled) and if I have to modify this generator, it will be quite a mess because it doesn't know the information stored in the mappings (a propos relationship between classes, especially). I thought Hibernate would automate the association stuff a bit more. I'm not complaining, I only find that surprising. According to me, this feature should be in the top ten position on the wish list.

Hibernate Team : the reason why this is not done is
  • a lack of time ?
  • a technical barrier ?
  • because user should know that they still have to do some things with their hands (as mentionned by ashneyde ;)

Ok, just kidding...

Thank you ashneyde and pksiv for your quick answer, I will now try to adapt it with my generator (more questions to come, I bet ;)

Best regards,
Joel.

PS : I would still like to know whether that auxiliary method [add(child)] will be added or not in future releases...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 10:26 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 10:47 am
Posts: 20
Location: Basel
Hum... I found that on the Wiki (here)
Quote:
Hibernate persists the parent and automatically persists its kids in the same transaction, being sure to set the parent's identifier in the parent_id field of the child so that it can be reconstituted in a future query.

If I read this well, the foreign key of a child (parent_id in the example) should be automatically updated by Hibernate. Is it right or wrong ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 10:32 am 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
[quote="joel"]Hum... I found that on the Wiki ([url=http://www.hibernate.org/209.html]here[/url])
[quote]Hibernate persists the parent and automatically persists its kids in the same transaction, being sure to set the parent's identifier in the parent_id field of the child so that it can be reconstituted in a future query.[/quote]
If I read this well, the foreign key of a child ([i]parent_id[/i] in the example) should be [u]automatically updated by Hibernate[/u]. Is it right or wrong ?[/quote]


nothing wrong with the stmt it is just a bit misleading. Since it does not tell explicitly, that all of those DB ops will be perfomred if you do the setting of the [b]OBJECT[/b] relationships correctly. If you read enough docs you will see that hibernate ppl refer to this many times just not in the doc you mentioned (or maybe even there but you missed it)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 10:56 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
joel wrote:
Hum... I found that on the Wiki (here)
Quote:
Hibernate persists the parent and automatically persists its kids in the same transaction, being sure to set the parent's identifier in the parent_id field of the child so that it can be reconstituted in a future query.

If I read this well, the foreign key of a child (parent_id in the example) should be automatically updated by Hibernate. Is it right or wrong ?


What this is trying to say is that Hibernate will set the ID in the Parent Object when it persists it. That way, if the Child has a reference to the Parent Object, it will see this value prior to being saved. If the Childs reference is NULL, it won't see the parent_id.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 11:02 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 10:47 am
Posts: 20
Location: Basel
Ok ok, I begin to see...
This is a bit embarrassing with the model I use because I'm very linked to org.hibernate.mapping.RootClass and I'm not able to call getAttrValue("id") : in the mapping, id is precisely an id and not a property so the getter Method is not filled. Well, I think I can handle this in a different manner.

Once again, thank you guys, you helped me a lot, even if that question seems quite obvious, it was a real pain in my neck.

Best regards,
Joel.


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