Hi Rob,
I'm facing with the following case:
Table:
public class Client implements Serializable {
@EmbeddedId
protected ClientPK clientPK;
...
@JoinColumns({
@JoinColumn(name = "cod_cpny", referencedColumnName = "cod_cpny", insertable = false, updatable = false)
, @JoinColumn(name = "username", referencedColumnName = "username")})
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Users User;
}
Primary Key:
@Embeddable
public class ClientPK implements Serializable {
@Basic(optional = false)
@Column(name = "cod_cpny")
private int codCompany;
@Basic(optional = false)
@Column(name = "cod_client")
private String codClient;
...
}
Users (follow the same pattern):
public class Users implements Serializable {
@EmbeddedId
protected UsersPK userPK;
...
}
@Embeddable
public class UserPK implements Serializable {
@Basic(optional = false)
@Column(name = "cod_cpny")
private int codCompany;
@Basic(optional = false)
@Column(name = "username")
private String username;
...
}
When I try to insert or update a Client, ebean does not include the field "username" in the generated SQL and it fails because this field is not null.
The field "cod_empr" is used as an tennant id (I'm yet not using @TennantId but planning in the future)
I think that is probable that "insertable = false, updatable = false" is causing this issue because if I comment it, it works.
I'm used to NetBeans 'Persistence->Entity Classes from Database' to reverse engineering the database to JPA
and it genarate that way, but after a while I created my own tool to reverse the database to include additional indexes, columns size,
default values, etc. to use dbmigration.
Question: Must I follow the JPA pattern with ""insertable = false, updatable = false" (and wait ebean follow JPA)
or is better to not include it and follow Ebean.
att
Edison Azzi