Strange behaviour of table with HbnContainer

Hi,

I’m still a noob with Vaadin and with Hibernate, but I saw strange behaviour using the Vaadin table with HbnContainer.
We have are using a onetoone and a onetomany relation, and we use the vaadin table to show the “grnadmother of all” side of the relations (Class Rsu) using an HbnContainer. When setting the fetchtype to EAGER of this relation, the Vaadin table shows not all objects, but most of the time the same object multiple times (exactly the total number of the items in the container). By dumping the container content itself (in a log) it contains the correct and expected objects (all different Rsu objects).


Class Rsu...
 @OneToOne( mappedBy = "rsu",  cascade = CascadeType.ALL)
  @JoinColumn(name = "TRAILDATAID", nullable = false, updatable = true,
    insertable = true)
  private TrailData trailData;

Class TrailData....
  @OneToMany(mappedBy = "traildata", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
 private Set<Trail> trails = new HashSet<Trail>(0);


By removing the EAGER fetchtype, the vaadin table shows the correct and expected values (Rsu’s). Can anyone explain what is happening here?

Hi,

it’s Hibernate “thing”. Please take a look to Hibernate FAQ under “Hibernate does not return distinct results for a query with outer join fetching enabled for a collection (even if I use the distinct keyword)?” [1]
.

Just override getBaseCriteria() with this:

@Override
protected Criteria getBaseCriteria() {
    return super.getBaseCriteria().setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
}

Best,
Maciej

[1]
https://community.jboss.org/wiki/HibernateFAQ-AdvancedProblems#Hibernate_does_not_return_distinct_results_for_a_query_with_outer_join_fetching_enabled_for_a_collection_even_if_I_use_the_distinct_keyword