I'm facing a problem with Ebean when trying to create Composed Keys (EmbeddedId).
This is a draft of what I have:
@Entity public class EntityA extends Model{
@Id
private String ID;
@OneToMany
private List<EntityB> listEntitesB;
public EntityA(){
ID = UUID.randomUUID();
}
}
@Entity public class EntityB extends Model{
@EmbeddedId
private EntityB_PK ID;
@ManyToOne
@JoinColumn(name="entityA_fk", referencedColumnName="listEntitiesB")
private EntityA entityA;
public EntityB(String entityB_ID){
ID = new EntityB_PK(UUID.randomUUID(), entityB_ID);
}
}
@Embeddable public class EntityB_PK{
private String entityB_ID;
private String entityA_FK_ID;
public EntityB_PK(String entB_ID, String entA_FK_ID){
entityB_ID = entB_ID;
entityA_FK_ID = entA_FK_ID;
}
}
Note: I'm using Ebean 4.1.4 with Java 1.6.
So, this code works well, but there is a perk, which I'm trying to solve - the resultant table in the database looks like this:
- entityB_ID [primary]
- entityA_FK_ID [primary]
- entityA_fk
As you can see that last column is redundant considering the "entityA_FK_ID" column.
What I would like to have?
- I would like to be able to tell Ebean to use the column "entityA_FK_ID" for the association @ManyToOne instead of creating it's own column.
To solve this problem we have to:
Here is the code:
EntityA.java:
EntityB.java:
EntityB_PK.java: