Hello,
I've a problem with Hibernate in my Webapplication. So I've a class Log with a unidirectional one-to-many reationship to LogEntries.
In Log:
In LogEntries, I've no reference to Log, because it's unidirectional.Code:@OneToMany(cascade=CascadeType.REMOVE, fetch=FetchType.EAGER) @JoinColumn(name="log_id") private final Set<LogEntry> logEntries = new HashSet<LogEntry>();
In my Example I use an instance of Log that contains 4 Instances of LogEntry. When I now load my Log instance, HibernateTemplate returns me a list that contains my Log four times... That's not what I expected.
It seems that every LogEntry loads the Log once more and at the end Hibernate finds four times the log. But it is four times the same instance.Code:public List<Log> findBy(Date logDate) { DetachedCriteria c = DetachedCriteria.forClass(Log.class); c.add(Restrictions.eq("logDate", logDate)); List<Log> logs = getHibernateTemplate().findByCriteria(c); return logs; }
What's going wrong?
Regards,
Mike


Reply With Quote