-->
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.  [ 6 posts ] 
Author Message
 Post subject: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 5:14 am 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
i'm using the latest hibernate release (3.5.beta.2) to test the latest JPA 2.0 features but i fail to create a bidirectional @OneToOne mapping with a derived id. whenever i try to do so hibernate will generate a BLOB as the id of the dependent entity. can someone point me to the right solution or a working example.

thank you very much in advance.

Code:
@Entity
public class A
{
    @Id @GeneratedValue
    private Long id;

    @OneToOne(mappedBy="a")
    private B b;
}


@Entity
public class B
{
    @Id @OneToOne
    private A a;
}

_________________
greetings,
kris


Top
 Profile  
 
 Post subject: Re: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 5:23 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Have you tried PrimaryKeyJoinColumn?


Top
 Profile  
 
 Post subject: Re: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 5:29 am 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
Yes i did, but then i get the following exception on startup (ddl update)

Quote:
Referenced property not a (One|Many)ToOne: B.a in mappedBy of A.b


any ideas? thanks

_________________
greetings,
kris


Top
 Profile  
 
 Post subject: Re: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 5:31 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
As shown in the examples you don't need a mappedBy anymore (your id-column is also the foreign-key, so no need to tell hibernate a mappedBy).

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 6:13 am 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
when i remove the mappedBy attribute the foreign-key is still created as BLOB (HsqlDB = VARBINARY) and i get an schema update error:

Quote:
[ERROR] SchemaUpdate Unsuccessful: alter table A add constraint FKC3B5EFE46F1961A6 foreign key (id) references B
[ERROR] SchemaUpdate Column types do not match in statement [alter table A add constraint FKC3B5EFE46F1961A6 foreign key (id) references B]


thanks for the help

_________________
greetings,
kris


Top
 Profile  
 
 Post subject: Re: creating bidirectional @OneToOne mapping with derived id
PostPosted: Mon Nov 23, 2009 6:52 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Please drop your database tables before testing, as something seems to be wrong with letting hibernate update it.

_________________
-----------------
Need advanced help? http://www.viada.eu


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