|
Team,
I too have been hitting this issue with a legacy DB. I tried the above fix and it brok other things. Upon further digging into the code etc. I came up with this...
@Entity
@Table(name="T_ACCOUNT")
public class Account.....
......
@ManyToOne(optional=true)
@JoinColumnsOrFormulas(value = {
@JoinColumnOrFormula(formula=@JoinFormula(value = "DATA_SOURCE_TYPE_CD", referencedColumnName = "DATA_SOURCE_TYPE_CD") ),
@JoinColumnOrFormula(column=@JoinColumn(name = "ACCOUNT_QUALIFIER_CD", referencedColumnName = "ACCOUNT_QUALIFIER_CD"))
})
private AccountQualifier accountQualifier;
@ManyToOne (optional=false)
@JoinColumn(name="DATA_SOURCE_TYPE_CD", referencedColumnName = "DATA_SOURCE_TYPE_CD" , nullable=false , unique=false , insertable=true, updatable=true)
private DataSourceType dataSourceType;
In my case the ACCOUNT_QUALIFIER_CD can be null in the T_ACCOUNT table, however both ACCOUNT_QUALIFIER_CD and DATA_SOURCE_TYPE_CD are NOT optional, NOT Nullable primary keys of the AccountQualifier class.
My JUnit tests save and load Account with both "null" and "not null" cases accountQualifier, resulting in null and not null values for ACCOUNT_QUALIFIER_CD column in the T_ACCOUNT table.
I will update related posts with this information...
Happy Coding , Jeff
|