Hi Jim...

Jim Clayson <[EMAIL PROTECTED]> writes:

> I have a one to many relationship between 2 entity beans: 
> User 1:N Car
> 
> The relationship is unidirectional ie User has a Set of Cars and a Car
> has no ref to its User.
> 
> The question is when I create a car, how do I update the list of cars
> a user has?

Assuming you're using xdoclet, you'll define abstract methods for your
car collection on UserBean that look something like this:

    /**
     * @ejb:relation      name="User-Cars"
     *               role-name="User-has-many-Cars"
     *        target-role-name="Car-belongs-to-User"
     *              target-ejb="Car"
     *   target-cascade-delete="yes"
     * @jboss:auto-key-fields
     */
    public abstract Set getCars();           
    public abstract void setCars(Set v);
    
You can create an add method to update the user's list of cars.

    /**
     * @ejb:interface-method
     */
    public void addCar (CarLocal car)
    {
        try {
            this.getCars().add (car);
        } catch (Exception e) {
            throw new EJBException (e);
        }
    }

Make sense?

-- Jim


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to