On 8/16/07, sparqle <[EMAIL PROTECTED]> wrote:
>
>
> I am using JPA-Hibernate and 2.0 M5. I have followed all of the upgrade
> notes.
> Now, if I have 2 classes (say class A and class B). Suppose an object of
> class A can contain one or many class B objects.
>
> If I have a method like this in my page controller:
> and suppose all the B objects have already been initialized with a
> reference
> to "a".
> saveObjects(A a, List bList){
>
> //In 2.0 M4, I was able to do this:
> getAManager().save(a);
> for(int i = 0; i<bList.size(); i++){
> B b =bList.get(i);
> getBManager().save(b);
> }
>
> //In 2.0 M5, I have to do this:
> a = getAManager().save(a);
> for(int i = 0; i<bList.size(); i++){
> B b =bList.get(i);
> b.setA(a); //EVEN THOUGH THIS IS ALREADY SET FOR B, but since "a"
> has been saved now, I have to
> //set it again, otherwise I get some very strange behavior with new
> objects of class A being created FOR EACH NEW B.
> //why is this required?
> b = getBManager().save(b);
> }
>
> }
In 2.0M5 the GenericDaoHibernate switched from using saveOrUpdate() to using
merge() as the method called to save an object. The latter has the advantage
that it does not blow up if an attempt is made to update an object that is
already in the session, but has the unfortunate side effect that the object
passed in to the call is not associated to the session - rather Hibernate
passes back an instance that is.
Also, the caching is working very strangely with m5. If I add another B to A
> (note that the A object is not updated at all, as B holds a reference to
> A),
> and I try to refresh my page with a tree listing of A and then all the Bs
> under it, the new B does not show up unless I initiate a new session. This
> was also working fine with m4.
As far as I know, no caching is implemented in AppFuse by default. You may
want to initiate a debug session to see what is going on. If object A is the
User object, something weird may be happening with User object cached in the
session. Or if you are caching the object in the session yourself, the issue
as above may be problematic.
Mike.
--
> View this message in context:
> http://www.nabble.com/2.0-M5-DAO-upgrade-issue-tf4280031s2369.html#a12182560
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>