'hibernate @Loader annotation on @oneToOne relation
I'm trying to implement a custom @loader using a namedQuery on a OneToOne - Relation of an entity. However the lastDatalog field remains null at all given times
I've tested the named query befor on a simple integration test using a repositry, the result was exactly what I intend to have in the lastDestinationStatus (I need the last updated record from the logs for this data and IREF combination)
when I query the Datalog entity with the id of the data I get the correct result so the Datalog entity seems to be persisted
maybe good to know : curent hibernate version on the project is 4.2.11.Final
this is en extract from entity 1
@Entity
@Table(name = "data")
@NamedQueries({
@NamedQuery(name = "LastLogQuery", query = "select log from DataLog log where log.data.id= ?1 and " +
"log.IREF = (select max(log2.IREF) from DataLog log2 where log2.data = log.data ) " +
"and log.tsUpdate = (select max(log3.tsUpdate) from DataLog log3 where log3.data = log.data and log3.IREF = log.IREF)")})
public class Data{
....
@OneToOne(targetEntity = DataLog.class)
@Loader(namedQuery = "LastLogQuery")
private DataLog lastDataLog;
}
extract from entity 2
@Entity
@Table(name ="log")
public class DataLog{
.......
@ManyToOne(fetch = FetchType.EAGER)
@org.hibernate.annotations.Fetch(value = org.hibernate.annotations.FetchMode.SELECT)
@JoinColumn(name = "DTA_IDN", nullable = false)
private Data data;
/** IREF */
@Column(name = "DSE_LOG_UID_FIL_REF_COD")
private String IREF;
@Column(name = "LST_UPD_TMS", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date tsUpdate;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
