Results 1 to 2 of 2

Thread: Instance found more than once

  1. #1
    Join Date
    Oct 2006
    Posts
    20

    Default 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. #2
    Join Date
    Oct 2006
    Posts
    20

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •