User
relates to Employee
as one-to-many.
The problem is the list of Employee
s within PeristentSet is empty.
It's seen from debug.
And it's at least one Employee
exists in DB for User
.
sql:
create table users(
id int not null primary key,
...
constraint `emp_constr` foreign key(`empid`) references `employee`(`id`));
User bean:
@ManagedBean
@SessionScoped
public class User {
private long id;
private List<Employee> employees = new ArrayList<Employee>();
...
user.hbm.xml config:
<list name="employees" cascade="all" inverse="false" fetch="join">
<key>
<column name="userid" not-null="true"/>
</key>
<index column="idx"/>
<one-to-many class="entry.Employee"/>
</list>
DAO call:
@Transactional
public List<User> getUsers() {
return sessionFactory.getCurrentSession().createCriteria(User.class)
.list();
}
Are there mistakes in .hbm.xml
file or I should add setFetchMode()
to DAO
explicitly?
EDIT :
I can get one sized collection only,in real it contains more elements with such config:
<list name="employees" table="employee" lazy="false">
<key column="userid" not-null="true"/>
<list-index column="idx"/>
<one-to-many class="entry.Employee"/>
</list>
that's because idx=0
if idx=7
collection size will be 8