You will need to explicitly tell it to cascade on a merge by setting the
cascade attribute on your join.
Mike.
On 8/24/07, p7k <[EMAIL PROTECTED]> wrote:
>
>
> no success in using merge(), no exceptions of any sort but nothing gets
> updated or removed.
>
> still looking for help.
>
> thank you!
>
>
>
> p7k wrote:
> >
> > Mike,
> >
> > Thank you for your reply. Any help is much appreciated. But I'm having
> > hard time translating your reply to my problem. Let me a little more
> > specific:
> >
> > 1. my Customer details form (view) allows for editing properties other
> > than the DistDay.
> >
> > 2. "e.g. adding a new day of the week to the list, then make sure you
> > load the
> > day of the week from Hibernate before adding it to the list" - but
> these
> > a simple value type enums, they might as well be integers, they are not
> > stored anywhere how would i go about loading them from hibernate?
> >
> > 3. could you elaborate on the use of merge(), especially in my case.
> > what do you mean "use the object returned from merge(), since all i want
> > to do with that object is either save or update it after the
> CustomerForm
> > has set all customer fields?
> >
> > 4. i don't have a DayOfWeekDao, since they are value types.
> > But, i do use customer = customerDao.saveCustomer(customer); ,
> following
> > the appfuse's CRUD tutorials.
> >
> >
> > Sorry, i'm a noob, i know ...
> >
> >
> >
> >
> >
> > Mike Horwitz wrote:
> >>
> >> On 8/23/07, p7k <[EMAIL PROTECTED]> wrote:
> >>>
> >>>
> >>> Please, help me learn !!!
> >>>
> >>> I have the following situation:
> >>>
> >>> a Customer class with a collection of enums which represent weekdays {
> >>> Sun,
> >>> Mon , Tue , ... }
> >>> ( in JSF, I bind these to a UISelectMany component - checkboxes )
> >>>
> >>> @Entity
> >>> public class Customer extends BaseLocation implements Serializable {
> >>> ...
> >>> private List<DaysOfWeek> distDays = new ArrayList<DaysOfWeek>();
> >>>
> >>> @CollectionOfElements( targetElement = DaysOfWeek.class )
> >>> @JoinTable( name = "Customer_DistDay" )
> >>> @Enumerated( EnumType.STRING )
> >>> @Column(name = "distDay", nullable = false)
> >>> public List<DaysOfWeek> getDistDays() { return distDays; }
> >>>
> >>> public void setDistDays(List<DaysOfWeek> distDays) { this.distDays=
> >>> distDays; }
> >>> ...
> >>> }
> >>>
> >>> I also have a CustomerForm action which is modeled exactly like
> >>> appfuse's
> >>> UserForm:
> >>> * edit() to initialize the backBean to an existing customer if (id !=
> >>> null)
> >>> or to a new customer;
> >>> * save(), which calls customer = customerDao.saveCustomer(customer) -
> >>> saveOrUpdate() with a flush();
> >>> * remove() calls remove from GenericDaoHibernate.
> >>>
> >>> I have been battling a long time to get the LazyLoading working:
> >>> * First, I enabled
> >>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter for
> >>> everything in my path:
> >>> This got me the viewing power both in CustomerList and CustomerForm.
> >>> Nayice!
> >>> I can "add" a new Customer.
> >>> I can't "update" (NonUniqueObjectException: a different object with
> the
> >>> same identifier value was already associated with the session ... )
> >>> I can't "delete"
> >>> (org.springframework.dao.InvalidDataAccessApiUsageException: Write
> >>> operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
> >>> ...
> >>> )
> >>>
> >>> * Second, without much thinking/understanding, I extended my
> >>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilterwith
> >>> the
> >>> recommended flush strategy from
> >>> http://wiki.apache.org/myfaces/Hibernate_And_MyFaces
> >>> http://wiki.apache.org/myfaces/Hibernate_And_MyFaces (it uses
> >>> FlushMode.COMMIT):
> >>> Now I got the views, "create" and "remove" working. SWELL
> >>>
> >>> BUT "update" does not work (NonUniqueObjectException: a different
> object
> >>> with the same identifier value was already associated with the session
> >>> ...
> >>> ).
> >>>
> >>> I suppose it's because the session, which contained it, no longer
> >>> exists.
> >>> So, hibernate thinks I'm being stupid, maybe I am.
> >>
> >>
> >> Usually the exception is thrown because the Session has previously
> loaded
> >> an
> >> object with the same id and you are trying to save a new, disconnected
> >> instance with exactly the same id. There are several ways to tackle
> this
> >> (best approach is largely determined by what goes on in your
> >> view/controller):
> >>
> >> 1) If all you are doing is adding objects to a list as part of your
> >> update,
> >> e.g. adding a new day of the week to the list, then make sure you load
> >> the
> >> day of the week from Hibernate before adding it to the list. That
> should
> >> make sure it knows the object you are trying to save is already
> >> associated
> >> with the session.
> >> 2) Use merge() rather than saveOrUpdate() as the method used to drive
> the
> >> update in your DAO. Just be careful here - you MUST use the object
> >> returned
> >> from the merge() method once it has been called, which means returning
> an
> >> object from your save method:
> >>
> >> e.g:
> >>
> >> DayOfWeek dayOfWeek = new DayOfWeek();
> >> dayOfWeek = dayOfWeekDao.save(dayOfWeek);
> >> ... continue using dayOfWeek instance.
> >>
> >> Mike
> >>
> >> Please, help !!
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/hibernate%3A-Lazy-Loading-101-tf4316007s2369.html#a12289186
> >>> Sent from the AppFuse - User mailing list archive at Nabble.com.
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/hibernate%3A-Lazy-Loading-101-tf4316007s2369.html#a12303838
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>