-->
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.  [ 7 posts ] 
Author Message
 Post subject: JBoss Web Service And Hibernate Lazy Loading problem
PostPosted: Tue Feb 03, 2009 9:31 am 
Newbie

Joined: Tue Feb 03, 2009 9:04 am
Posts: 2
Hello there.
In my current project,I have to use web service as the RPC method。So the loaded object must be transformed to XML SOAP. My problem is when the jboss server try to that, I would get the lazy loading after session closed exception because some properties are not loaded when the session is open and I don't want them to be loaded either. So I wonder if there is any method I can make the getProperties() call silently return null instead of throwing an exception?

Any response would be highly appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 5:05 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
First, you should render your web service response within the scope of a transaction so that you don't have this problem. Second, you can tell if something is loaded by using Hibernate.isInitialized():

http://www.hibernate.org/hib_docs/v3/ap ... ang.Object)

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 9:09 pm 
Newbie

Joined: Tue Feb 03, 2009 9:04 am
Posts: 2
Thank you for your answer, but it doesn't help.
If I make the web service response rendered within the transaction, the response would contain too much collection properties that I don't want actually. The problem is, I DON'T want them!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 12:40 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
dude

try to utilize filters. i used this technique long time ago but in this case u have to make sure about the transactions


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 3:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
superc wrote:
Thank you for your answer, but it doesn't help.
If I make the web service response rendered within the transaction, the response would contain too much collection properties that I don't want actually. The problem is, I DON'T want them!

Before rendering the response you could detach these objects and set all associations, which you don't want to null.
Anyway, I have not much experience about webservices, but there surely is a possibility to determine which fields to map to the response and which not, isn't there?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 6:13 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Have you considered providing the Web service with a decorator object that encapsulates access to your real persisted object?

That way you can pick and choose what you allow the service to see.


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 10:42 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Also, letting what is fetched and what isn't determine the contract of your web service sounds like trouble to me. Imagine if you change a mapping that affects loading, then you all of a sudden break your clients.

Whatever is rendering your web service (you said it was JBoss, that sounds like a SLSB to me, so it would be inside a transaction) should know what it needs to return and just consume whatever data it needs. The fact that the data is or is not initialized should not matter at all.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.