Hi,
I have a relation like that ;
Person <OneToMany> Home
Home <OneToMany> Room
I load a group of Person. So Hibernate generate :
A) 1 SQL for load the group of Person (for exemple 10 person)
B) 10 SQL for loading the Home of each person (for exemple 5 home/person)
C) 5 * 10 SQL for loading the Room
So I want load all Person in single SQL, all Home in single SQL and all Room in single SQL.
I try this mapping :
Code:
@Entity
class Person {
@OneToMany(fetch=FetchType.EAGER, mappedBy = "person")
@OrderBy("index ASC")
@JoinColumn(name = "personId")
@IndexColumn(name="someIndex")
@Fetch(FetchMode.SUBSELECT)
private final List<Home> homes;
...
}
@Entity
class Home {
@OneToMany(fetch=FetchType.EAGER, mappedBy = "room")
@OrderBy("index ASC")
@JoinColumn(name = "homeId")
@IndexColumn(name="someIndex")
@Fetch(FetchMode.SUBSELECT)
private final List<Room> rooms;
@ManyToOne
@JoinColumn(name="personId")
private Person person;
...
}
@Entity
class Room {
@ManyToOne
@JoinColumn(name="homeId")
private Home home;
...
}
I want stay in EAGER mode.
So, Hibernate still generate a lot of SQL. It is normal? Or, I'm sure, I don't uderstand how the @Fetch(SUBSELECT) work.
JPA
Java 1.5
Hibernate Annotations 3.3.1.GA
Hibernate 3.2.6
Hibernate EntityManager 3.3.2.GA
Oracle
hibernate.dialect=org.hibernate.dialect.Oracle8iDialect
hibernate.show_sql=true
hibernate.max_fetch_depth=3
[/code]