users@glassfish.java.net

Re: One to One Mapping

From: <glassfish_at_javadesktop.org>
Date: Wed, 18 Jun 2008 07:23:34 PDT

Hello Steve,

String is a valid Id field type, and there are many examples showing it being used. A bidirectional OneToOne relation should be set up the same way regardless of the Id field type:

@Entity
Class A
..
  @Id
  String id;
  @OneToOne(mappedBy="a")
  public B b;
}
@Entity
Class B
..
  @OneToOne
  public A a;
}

This should use a foreign key field in Table B called A_ID of type string. If this is what you have, you might try checking the types that are in the database to see if somehow your fk field is different from what you would expect.

I'm not familar with Hibernate, so you mght want to try posting to a Hibernate forum, or try with another provider to see if you get the same problem.

Best Regards,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=281033