Hallo,
ich habe eine Problem mit einer One-To-One Beziehung, die nicht geladen wird, obwohl ich FetchMode.JOIN angegeben habe:
Code:
@Entity
@Table(name="DATA")
public class Data implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
......
@OneToOne (cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn (name = "data_id")
private Score score = null;
@OneToMany (targetEntity = TextData.class, mappedBy = "Data", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<TextData> schufaTextData = new HashSet<TextData>(0);
.....
Code:
@Entity
@Table(name="SCORE")
public class Score implements java.io.Serializable {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name="attribute_code")
private String attributeCode;
@Column(name="description")
private String description;
@Column(name="score_value")
private int scoreValue;
@Column(name="risk_rate")
private float riskRate;
@Column(name="score_range")
private String scoreRange;
@Column(name="text")
private String text;
@OneToOne (targetEntity = SchufaData.class)
@JoinColumn (name = "data_id")
private Data data;
....
Ich lade die Sachen mit Spring und Hibernate:
Code:
@SuppressWarnings("unchecked")
public List<Data> findDataByIpNbrLess24h(String ipNbr) {
final String finalIpNbr = ipNbr;
return (List<Data>)getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Calendar critDateTime = Calendar.getInstance();
critDateTime.set(Calendar.DATE, critDateTime.get(Calendar.DATE)-1);
Criteria criteria = session.createCriteria(Data.class);
criteria.add(Restrictions.and(Restrictions.eq("ipNbr", finalIpNbr),
Restrictions.gt("insertDate", critDateTime.getTime())));
criteria.setFetchMode("score", FetchMode.JOIN);
criteria.setFetchMode("textData", FetchMode.JOIN);
return criteria.list();
}
});
}
Die TextData Liste wird einwandfrei geladen, die One-To-One Beziehung nicht. Hat jemand eine Idee was ich falsch mache?