[jboss-user] [EJB 3.0] - Problem with FetchType.EAGER - multiple instances of an obje

reubenf do-not-reply at jboss.com
Tue Nov 14 17:24:09 EST 2006

I have a class named Item that contains a list of objects of type Algorithm. The list is defined with the following property and mapping:

@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, targetEntity=Algorithm.class)
    joinColumns = { @JoinColumn( name="item_id") },
    inverseJoinColumns = @JoinColumn( name="algorithm_id")
public  List getAlgorithms() {
    return algorithms;

I have a unit test that creates an Item with three Algorithms and then retrieves the Item with its Identifier

List itemIDs = new ArrayList(1);
Criteria criteria = session.createCriteria(Item.class);        
criteria.add(Restrictions.in("itemIdentifier", idValues));
		List entities = criteria.list();
With fetch=FetchType.EAGER - the returned list has 3 items
With fetch=FetchType.LAZY - the returned list has 1 item

The retrieved list should return only 1 item. The result should not be different based on the fetch strategy. It looks as if the query in the EAGER case does an outer join yielding 3 records and then creates 3 Items.

Can anyone please explain what I may be doing wrong?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3985954#3985954

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3985954

More information about the jboss-user mailing list