This content has been marked as final.
Show 2 replies
-
1. Re: Question about OneToOne relationships where other table'
ycswyw Dec 4, 2005 1:15 PM (in response to dbudworth)If you don't want the unused "UserDetail" column and sequence , you can try with this code (not tested)
class User{
@Id
@Column(name="user_id")
Long userId;
@OneToOne(optional = true)
@JoinColumn(name="user_id")
UserDetail detail;
}
class UserDetail{
@Id(generate = GeneratorType.NONE)
@Column("user_id")
Long userId;
@OneToOne()
@JoinColumn(name = "user_id")
User user;
}
But you must also have to set the Id on the slave:
i.e:
@PersistenceContext
private EntityManager manager;
public void test() {
user = new User();
manager.persist(user);
UserDetail detail = new UserDetail();
detail.userId = user.userId;
detail.user = user;
manager.persist(detail);
} -
2. Re: Question about OneToOne relationships where other table'
epbernard Dec 30, 2005 7:33 PM (in response to dbudworth)this is doable I think using the @GenericGenerator and the foreign strategy