-->
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.  [ 5 posts ] 
Author Message
 Post subject: "foreign" GeneratorType and one-to-one by PK
PostPosted: Wed Nov 09, 2005 10:47 am 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
In http://hibernate.org/~emmanuel/doc/#gen21 I found the following:


Quote:
Unfortunatly, in the current release of Hibernate Annotations, the Heart identifier value has to be set manually by the application developer. Support for a Hibernate-style "foreign" identifier generator will be added soon.


I wonder what is the status of this and how it relates to ejb3?

([url]http://www.jboss.com/index.html?module=bb&op=viewtopic&t=72070
[/url])

Thanks![/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This doc is very obsolete, use the one in the web site please.
This shold work but not in a standard EJB3 way

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 4:59 pm 
Newbie

Joined: Fri Apr 01, 2005 2:09 pm
Posts: 1
I am not having success with this. Looking at the unit test for the Body/Heart one-to-one relationship it doesn't appear as if this functionality is actually tested (note how the ID is manually set in Heart):

Code:
   public void testUnidirectionalTrueOneToOne() throws Exception {
      Body b = new Body();
      Heart h = new Heart();
      b.setHeart(h);
      b.setId( new Integer(1) );
      h.setId( b.getId() ); //same PK
      Session s;
      Transaction tx;
      s = openSession();
      tx = s.beginTransaction();
      s.persist(h);
      s.persist(b);
      tx.commit();
      s.close();

      s = openSession();
      tx = s.beginTransaction();
      b = (Body) s.get( Body.class, b.getId() );
      assertNotNull(b);
      assertNotNull( b.getHeart() );
      assertEquals( h.getId(), b.getHeart().getId() );
      tx.commit();
      s.close();

   }


I have two classes defined in much the same way as the Body/Heart example (except I have @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)) and I get the following error:

Code:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri Feb 10, 2006 12:55 pm 
Newbie

Joined: Thu Sep 09, 2004 6:50 am
Posts: 15
you need to use the custom forign generic generator:

@Id @GeneratedValue(generator="foreign")
@GenericGenerator(name="foreign", strategy = "foreign", parameters = {@Parameter(name="property", value="propName")})


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 10:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
can somebody sommarize that on the annotations FAQ?

_________________
Emmanuel


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