-->
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: Problem with ForeignGenerator?
PostPosted: Tue Jan 03, 2006 7:06 pm 
Newbie

Joined: Thu Dec 29, 2005 8:42 pm
Posts: 8
I have an entity that has a one-to-one relationship with another entity, i.e. (ommitting a bunch of mandatory stuff for the sake of brevity):

Code:
<class entity-name="AnEntity">
  <id name="primaryKey">
    <generator class="foreign">
      <param name="property">aProperty</param>
    </generator>
  </id>
  <one-to-one name="aProperty" entity-name="AnotherEntity"/>
</class>

I then create a detached (aka transient) instance of AnEntity with an embedded detached instance of AnotherEntity with both of their id's set to null and then do a saveOrUpdate(). Hibernate then throws an 'unknown entity mapping exception with the classname of the instance of AnotherEntity. Tracing into the code ForeignGenerator.generate() calls session.save as follows:

Code:
  Serializable id;
  try {
   id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
    type.getAssociatedEntityName(),
    associatedObject,
    sessionImplementor);
  } catch (TransientObjectException toe) {
    id = session.save(associatedObject);
  }


If looks like if it were modified as follows, it might work?

Code:
  Serializable id;
  try {
   id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
    type.getAssociatedEntityName(),
    associatedObject,
    sessionImplementor);
  } catch (TransientObjectException toe) {
    id = session.save(type.getAssociatedEntityName(), associatedObject);
  }


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.