-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Delete + load does not work as intended
PostPosted: Mon May 02, 2005 2:30 pm 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
Hi there,

I am migrate to Hibernate 3.0. I have a problem with a very simple test case.

The test reads:

Code:
Product product=catalog.create("name");
flush();
catalog.remove(product);
flush();
clear(); //just added to be sure, I do everything right

assertNull("Product should not exist anymore", catalog.getProduct(product.getProductId()));


I played with evict(product) and clear(). But everytime I use getProduct I still get the already deleted product. GetProduct uses Session.load(Product.class, productId). If I call refresh(product), Hibernate complains about 'no row with index productId'.

Anyone having any idea?


Cheers,

Martin (Kersten)



Hibernate version: 3.0

Name and version of the database you are using: PostgreSql 8.0
[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 3:42 pm 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
I would like to add that the problem comes down to:

Code:

Product product=new Product();
session.save(product);
session.flush();

session.delete(product);
session.flush();

session.load(Product.class, product.getProductId()); //this should fail/return null


So deleting a product (which should result of removing product from datastore), the product is still returned by the session.load method. I would expect a failure like it happend with session.refresh(product). There is no row in the table matching the productId and therefore no product should be returned by the load method.


So the question goes, if I miss something here?


Cheers,

Martin (Kersten)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 4:16 pm 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
I digged into the hibernate code and found the problem. It lies in the option allowProxyCreation (DefaultLoadListener.onLoad()).

Using the load method, it seams to make it possible to use a proxy and only access the database if the proxy is accessed. Maybe this is a method of providing additional optimizations (loading more then one proxy but fetch all at once, once any of those proxies is accessed, but I am not sure, didn't digged that far).

At the end, it turns out, that the solution lies in triggering a method path(message chain) to end with the option allowProxyCreation being set to false.

This makes it possible:

Code:
else if ( loadType == GET ) {
         options.setAllowNulls(true);
         options.setAllowProxyCreation(false);
         options.setCheckDeleted(true);
         options.setImmediateLoad(false);
      }


So all that I should do is using SessionImpl.get(..) instead of SessionImpl.load(..).

I tried it and problem solved... . Sorry for disturbing you.


Cheers,

Martin (Kersten)


Top
 Profile  
 
 Post subject: Re: Delete + load does not work as intended
PostPosted: Fri Jun 29, 2012 4:06 pm 
Newbie

Joined: Thu Jan 26, 2012 11:56 am
Posts: 9
forever alone! XD

_________________
-------------------------------------------------------------
http://javahelp.redsaltillo.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.