How many Test objects are there in the database?  5 I'm guessing...

ros wrote:
(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.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to