Can someone explain me why using the annotation @Fetch(FetchMode.SELECT) allows me to use Lists instead of Sets? Which is the difference by using other fetchmode types like SUBSELECT?
Here below a piece of exmple code:
class One{
..
@Fetch(FetchMode.SELECT)
@OneToMany(mappedBy="one", fetch = FetchType.EAGER, ... )
private List<Something> listOne = new ArrayList<Something>();
@Fetch(FetchMode.SELECT)
@OneToMany(mappedBy="one", fetch = FetchType.EAGER, ... )
private List<SomethingElse> listTwo = new ArrayList<SomethingElse>();
...
}
In this way it works but I’d like to know why….I found other discussion with alternatives solutions but this one wasn’t the preferred one…
You should be able to use
ListorSetas the interface for your collection, it has nothing to do with fetching.@Fetch(FetchMode.SELECT)together withfetch = FetchType.EAGERmeans that after loading theOneentity hibernate will immediately issue a second select to load list.The
@Fetch(FetchMode.SUBSELECT)withoutfetch = FetchType.EAGERmeans that hibernate will load the list with a subselect for all one enitities (they might also be part of a collection) when accessing the first list element(List<SomethingElse>).