(Appguse2 Hibernate)
I've added OneToMany relation with FetchType.EAGER from User pojo to Test
pojo.
Now GenericDaoHibernate getAll returns 5 users, but in database there are 2
users - one amin user and one tomcat user, tomcat user has relation to 4
Test pojos.
Can getAll return distinct selection of users?
@Entity
@Table(name="app_user")
public class User extends BaseObject implements Serializable, UserDetails {
...
protected Set<Test> tests = new HashSet<Test>();
...
@OneToMany(targetEntity=Test.class, cascade=CascadeType.ALL,
mappedBy="user", fetch = FetchType.EAGER)
public Set<Test> getTests() {
return testss;
}
...
}
test:
GenericSearchDaoHibernate<User, Long> searchDao = new
GenericSearchDaoHibernate(User.class);
searchDao.setSessionFactory((SessionFactory)
applicationContext.getBean("sessionFactory"));
List<User> users = searchDao.getAll();
System.out.println(users.toString());
output:
[EMAIL
PROTECTED],enabled=true,accountExpired=false,credentialsExpired=false,accountLocked=false,Granted
Authorities: ,user],
[EMAIL
PROTECTED],enabled=true,accountExpired=false,credentialsExpired=false,accountLocked=false,Granted
Authorities: ,user],
[EMAIL
PROTECTED],enabled=true,accountExpired=false,credentialsExpired=false,accountLocked=false,Granted
Authorities: ,user],
[EMAIL
PROTECTED],enabled=true,accountExpired=false,credentialsExpired=false,accountLocked=false,Granted
Authorities: ,user],
[EMAIL
PROTECTED],enabled=true,accountExpired=false,credentialsExpired=false,accountLocked=false,Granted
Authorities: ,admin]]
If relation is FetchType.LAZY then no duplicate users, but I need to load
Test pojos with user.
--
View this message in context:
http://www.nabble.com/apfuse2%2Bhibernate---GenericDaoHibernate-getAll-returns-duplicate-entities-%28users%29-tf3227657s2369.html#a8966242
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]