I had a second look on your answer, and I think I can formulate my problem based on
the code proposed by you:
I would like to know why
* @ejb.finder * signature = "java.util.Collection findPhoneOfUser(UserLocal user)" * query = "SELECT OBJECT(p) FROM phone p WHERE p.getUser = ?1 "
is not working.
In Detail:
1. User and Phone are entity beans.Yes, this is what I am going to, adapted to your Phone/User example.
2. Phone and User have a 1:N relationship. Each P has a U, and thus a U
also has
many Ps that consider them as their U. 3. The User table has a PK column called id.
4. The Phone table has a FK column called user.
If those are all correct, then you need to change your xdoclet tags to specify a relationship instead of a field. For example, for User <-- 1:N --> Phones, here are the tags I use in UserEJB.java:
/** * @ejb.interface-method * @ejb.transaction type="Supports" * @ejb.relation * name="User-Phone" * role-name="User-has-many-Phones" * cascade-delete="no" */ public abstract Collection getPhones ( ) ; public abstract void setPhones ( Collection phones ) ;
And in PhoneEJB.java:
/** * @ejb.interface-method * view-type="local" * @ejb.transaction type="Supports" * @ejb.relation * name="User-Phone" * role-name="Phones-have-a-User" * cascade-delete="yes" * @weblogic.column-map * foreign-key-column="user_id" * key-column="id" */ public abstract UserLocal getUser ( ) ;
/** */ public abstract void setUser ( UserLocal user ) ;
This is for a bidirectional relationship, so both beans know about and can find each other via relationships and in finder queries. I also added a helper method so I could hook a Phone up to a User given only the User's ID:
/** * Attaches this phone to the user with the given ID. * * @param userId unique ID of the owning user */ protected void setLocalUserId ( Integer userId ) { try { setUser(UserUtil.getLocalHome().findByPrimaryKey(userId)); } catch ( NamingException e ) { throw new ServiceException("Failure looking up user home", e); } catch ( FinderException e ) { throw new ServiceException("Failure finding a user", e); } }
First of all, is this where you were going with this?
Now I would like to make a finder method on phones, where I select those (the single one in fact) having a certain
user:
* @ejb.finder * signature = "java.util.Collection findPhoneOfUser(UserLocal user)" * query = "SELECT OBJECT(p) FROM phone p WHERE p.getUser = ?1 "
This is not working in my examples. Why?
Best, and thanks again, Philipp
smime.p7s
Description: S/MIME Cryptographic Signature
