-->
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: OneToOne relationship - Provided id of the wrong type
PostPosted: Fri Aug 28, 2009 9:18 am 
Newbie

Joined: Wed Aug 26, 2009 3:00 am
Posts: 3
Location: Naples, IT
Hi to all!

Sorry for the newbie question, but I have a problem with a OneToOne relationship.

I have this situation in a legacy DB that i can't modify:
A
(fieldOne, fieldTwo, x) PK
foo

B
(fieldOne, foo, y) PK

The OneToOne relationship that I have to implement is on:
A.foo=B.foo

The java code is:
Code:
@Entity
@Table(name = "A")
public class A implements java.io.Serializable {
    private AId id; // it contains 'fieldOne', 'fieldTwo' and 'x'
    private int foo;

    private B b; // 1-to-1 relationship with B

    // .. code ..

    @OneToOne(mappedBy="a", targetEntity=B.class)
    public B getB(){ ... }

    public void setB(B b){ ... }


Code:
@Entity
@Table(name = "B", uniqueConstraints = @UniqueConstraint(columnNames = "ID"))
public class Bimplements java.io.Serializable {
    private B BId; // it contains 'fieldOne', 'foo' and 'y'.
    private A a;   // 1-to-1 relationship with A


    // .. code ..

    @OneToOne(targetEntity=A.class)
    @JoinColumn(name="FOO") // the name of the property foo in the table A.
    public Ress getA() { ... }

    public void setA(A a){ ... }


But this implementation raises:
Exception in thread "main" org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class db.AId, got db.BId

And .. I simply don't understand why!

Thanks a lot!

_________________
Stay hungry, stay foolish.


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.