Hello
I'm backing my legacy system using hibernate.
The issue is related to a table with data records that are versionned.
Ie:
Code:
table VALUES_HISTORY
--------------------------------------------------------------------------
| Functional_Key | Valid_from | valid_to | data_one | ...
--------------------------------------------------------------------------
| FKONE | 2007-01-01 | 2007-07-12 | XXXXX | ...
| FKONE | 2007-07-13 | 2099-12-31 | XXXXX | ...
| FKTWO | ...
I map the bean LastValue to the table VALUES_HISTORY, and specify a @where clause to get only the last valid value.
Code:
@Entity
@Table(name = "VALUES_HISTORY")
@Where(clause = "valid_to = '2099-12-31')
public class LastValue {
@Id
@Column(name = "Functional_Key")
private String functionalKey;
***
}
When I retrieve the bean through a finder, the @where clause is taken into account, aka the generated select includes valid_to = '2099-12-31'
The issue is when I use the entity as a FK object
ie
Code:
@Entity
@Table(name = "TABLE_WITH_VALUE")
public class ModelWithFk {
***
@ManyToOne
@JoinColumn(name = "Last_Value")
private LastValue lastValue ;
***
}
When I retrieve a ModelWithFk using a Dao, I can see that the generated SQL does not contain the @Where clause specified for the LastValue bean. Hibernate then throws an exception if there is more than one record in VALUES_HISTORY for the specified value.
Could you tell me if this is an hibernate bug or if I made a mistake in the way I map beans.
Thanks in advance !!!