This is a situation I want to represent in my PLAY project:
table clients {
client_id (pk),
description
}
table items {
client_id (fk, pk),
item_id (pk)
}
In the 'items' table I want to have a composite primary key that will consist of combined client_id and item_id. I have read JPA documentation as well as many posts on the topic but everything fails again and again. This is one of many versions I have tried - closest to the JPA documentation.
@Entity
@Table(name = "items")
public class Items extends Model {
ItemsPK primaryKey;
public Items() {
}
@EmbeddedId
public ItemsPK getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(ItemsPK pk) {
primaryKey = pk;
}
}
@Embeddable
public class ItemsPK implements Serializable {
private long itemId;
private Client client;
public ItemsPK() {
}
@Column(name = "item_id")
@GeneratedValue(strategy = GenerationType.AUTO)
public long getItemId() {
return itemId;
}
public void setItemId(long itemId) {
this.itemId = itemId;
}
@ManyToOne
@JoinColumn(name = "client_id", nullable = false)
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
//public int hashCode() {...
//public boolean equals(Object obj) {...
}
The above code (as well as many other different setups) produce following error during play launch:
java.lang.RuntimeException: Error reading annotations for models.ItemsPK at com.avaje.ebeaninternal.server.deploy.parse.ReadAnnotations.readAssociations(ReadAnnotations.java:73) ~[ebean.jar:na] at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDeployAssociations(BeanDescriptorManager.java:1100) ~[ebean.jar:na]
I don't have a clue what might be wrong with my code. I'm starting to think that it is a PLAY bug. Any ideas?