Hello Emmanuel,
At the end of this message, I've included some test code that incorporates your above suggestion (as I've interpreted it, which in itself could be an issue).
The resulting DDL creates two tables that seem to be completely unrelated (they have the the same primary key, persumably because they share the same EntityKey object).
What I would like to be generated is EntityA with a primary key of 'id' (no other fields) and EntityB with a foreign key of 'id' and a single field called text.
I notice that when I put the @OneToOne annotations on the getter versus the member attribute, I get two blobs created in each table representing the other object.
Am I doing something wrong?
Thanks,
Matthew
Class: EntityA
Code:
@Entity
public class EntityA implements Serializable
{
@EmbeddedId
private EntityKey key;
@OneToOne @PrimaryKeyJoinColumn
private EntityB entityB;
public EntityA()
{
}
public EntityB getEntityB()
{
return entityB;
}
public void setEntityB(EntityB pEntityB)
{
entityB = pEntityB;
}
public EntityKey getKey()
{
return key;
}
public void setKey(EntityKey pKey)
{
key = pKey;
}
}
Class: EntityBCode:
@Entity
public class EntityB implements Serializable
{
@EmbeddedId
private EntityKey key;
private String text;
@OneToOne(mappedBy="entityB", optional = false)
private EntityA entityA;
public EntityB()
{
}
public String getText()
{
return text;
}
public void setText(String pText)
{
text = pText;
}
public EntityA getEntityA()
{
return entityA;
}
public void setEntityA(EntityA pEntityA)
{
entityA = pEntityA;
}
public EntityKey getKey()
{
return key;
}
public void setKey(EntityKey pKey)
{
key = pKey;
}
}
Class: EntityKeyCode:
@Embeddable
public class EntityKey implements Serializable
{
private long id;
public long getId()
{
return id;
}
public void setId(long pId)
{
id = pId;
}
}