Code:
List<AcctUser> acctUsers = user.getAccountUsers();
uhm, this is what I would like to have as a method and do NOT have right now ;) because of the table design so turning on sql logging does not help. ps. Use log4jdbc instead of hibernate's logging...it is much much better as it gives the params and easy to hook up ;). that is what we use as it gives way more detail(you can even cut and paste sql into an sql program except for dates).
Quote:
Please write down the columns of all three tables, and also write down which column you want to select.
3 tables should be enough to get the picture...
acctuser table has 3 columns (accountno/acct2user is the PK)
accountno
acct2user (this has the same as user tables objid below...quite stupid).
data
user table has (userid is the PK)
userid(PK)
objid (this matches acctuser.acct2user above).
other columns
roles table
id (PK)
userid (FK)
role
As you can see, what I did was add this method to user :(....
Code:
public List<AcctUser> getAccountUsers(EntityManager mgr) {
Query query = mgr.createNamedQuery("findAccountUsersByUser");
query.setParameter("user", this);
return query.getResultList();
}
where HQL is something like
select au from Users u, AcctUser au where u.objid = au.acct2user and u = :user
What I wanted was a way to have a getAccountUsers method without passing the EntityManager in so I didn't have to refactor all the client code later that passes in the EntityManager.