Announcement Announcement Module
Collapse
No announcement yet.
Instance found more than once Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Instance found more than once

    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:
    Code:
    @OneToMany(cascade=CascadeType.REMOVE, fetch=FetchType.EAGER)
        @JoinColumn(name="log_id")
        private final Set<LogEntry> logEntries = new HashSet<LogEntry>();
    In LogEntries, I've no reference to Log, because it's unidirectional.

    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.

    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;
     }
    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.

    What's going wrong?

    Regards,

    Mike

  • #2
    Ok, I've found the solution.

    It works as designed. The description can be found here:

    http://www.hibernate.org/117.html#A12

    Regards,

    Mike

    Comment

    Working...
    X