-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: @ManyToMany problem and relations between several classes
PostPosted: Fri Jan 27, 2006 11:09 am 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
With only one HistoryEntry, one EForm, one EFormConf, and a few EFormConf approvers and admins; I get around 40 history entries listed for the one form. When my code creates and saves the objects, the database has the proper data, but when it loads it and I display it there are far too many HistoryEntries

Hibernate version: 3.1.1, annotations 3.1beta8

Mapping documents:
Code:
@Entity
public class HistoryEntry implements Serializable {
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   protected long id;

   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="eform", insertable = false, updatable = false)
   protected EForm eform;

   protected String action;
   ...
}


@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class EForm implements Serializable {
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   protected long id;

   @ManyToOne
   protected EFormConf conf;
   
   @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
   @JoinColumn(name="eform")
   @OrderBy("datetime")
   protected List<HistoryEntry> history = new ArrayList<HistoryEntry>();

   @Enumerated(EnumType.STRING)
   protected Status status = Status.DRAFT;

   @ManyToOne
   protected Person creator;
   ...
}

@Entity
public class EFormConf implements Serializable {
   
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   protected long id;
   
   @Column(unique = true)
   protected String name;

   @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @JoinTable(name="tblEFormConfApprovers")
   @IndexColumn(name = "approval_order", base=1)
   protected List<Person> approvers = new ArrayList<Person>();


   @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @JoinTable(name="tblEFormConfAdmins")
   protected List<Person> admins = new ArrayList<Person>();
   ...
}


Code between sessionFactory.openSession() and session.close():

Using spring hibernate support, I do:
Code:
form = getHibernateTemplate().get(MyForm.class, key);

where MyForm extends EForm, and key is a long

And then iterate through the HistoryEntries of
Code:
getForm().getHistory()


Name and version of the database you are using: MSSQL Server 8.0

The generated SQL (show_sql=true):

It's huge, joining between all tables. Our "Person" table has dozens of columns and is joined to several times.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 9:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do not eagerly fetch more than one collection per reultset or use Set Collection (is not involving a bag semantic)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 11:07 am 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
emmanuel wrote:
Do not eagerly fetch more than one collection per reultset or use Set Collection (is not involving a bag semantic)

Thanks. I am not able to use lazy loading at this point (I'm working on it, but using a portlet environment is making it difficult) so I'll see what I can do.

Is this a bug, or an inherent limitation of eager loading?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it's a inherent limitation of using the bag semantic twice in a single resultset

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 6:26 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
emmanuel wrote:
it's a inherent limitation of using the bag semantic twice in a single resultset

Is there documentation for this?

I changed all my bag semantics to list or set semantics, but with the same results. Is it okay to have multiple collections using the list semantic?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 6:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In the doc, there is a table summarizing how to do List semantc, have a look. I'm pretty sure you did not set the @IndexColumn

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 12:26 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
emmanuel wrote:
In the doc, there is a table summarizing how to do List semantc, have a look. I'm pretty sure you did not set the @IndexColumn


Yes, I've seen that table. I did try changing that List to a Set, so now I don't have any bag semantics. Does the limitation apply only to bag semantics?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 4:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.