-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: lazy loading again
PostPosted: Wed Feb 01, 2006 7:29 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
Hi all,

I am having lazy loading problems that I cannot solve with the open session pattern. My problem is a lot like http://forum.hibernate.org/viewtopic.ph ... light=lazy

But i am not using swing, instead i use a component based web framework. The solution offered in the post i refer to does not suite my situation i think (session forever).

The framework stores a lot of objects that are used in another request again. There is no way for me to do nifty initialization without spending months. Is there a way to re-attach objects when they are not bound anymore. I'v been thinking about this for a while and there is nothing I can think of appart from fully loading everything always but that's is certainly not what i want.

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 8:16 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
A good way to solve this problem is to share identifiers instead of persistent objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 8:55 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
Thanks for your reaction. If I had to setup a new application I would not have a problem because I would work like you suggest. I am trying to use hibernate in an existing aplication though and there are to many objects that keep state and refer eachother. If I have to implement the identifier pattern I will lose weeks if not months on it to fix it all.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:11 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Probably it depends on appilcation design, but it must possible to refactor infrastructure or communication related code in a few hours (I assume it doe's not depend on domain specific logic).
If you can post more specific information then probably somebody can help (there is a lot of collective expierence on this forum)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 7:47 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
I use a component based view framework. The view components can be backed by a persistent object. Once the application component tree is build it is rendered on every request and stored in memory with the references to the persistent object. I can make sure that the getter for the persistent object performs a check but I dont know how to ask if an object is not bound. The only thing I can think of is to catch the exception and load again.

I also map the db schema as persistent objects, it is basically the same as storing hbm files in the database. I use it as way to do meta programming. Every persistent object holds reference to it's meta object. I believe the problem is in the view components holding reference to the persistent objects. I wrapped some calls in a try catch but it keeps on going wrong.

When i do a get on a collection i cannot intercept without wrapping every call to the collection in a try catch block. Is it not possible to do some custom interception somehow?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 2:04 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
If this is JSF then it must be possible to rebuild component tree per request, global cache must help for performance and concurrency.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 5:21 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
what is the problem to intialize the objects you want to show,

either using
left join fetch with HQL
or
setFetchMode with criteria queries.

When your component is some kind of static JSP, you will have a round trip anyway. Or is the component bild of Javascript?

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 7:56 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
It is not jsf , it is a lot like wicket. Rebuilding the tree is exactly what i dont want because I lose a lot of performance. setFetchMode with criteria doesn't help me out because I never know upfront what is needed. If I fetch everything eager then I would have no lazy loading at all anymore. What I need is a custom interceptor on certain classes. It is also tempting to hack hibernate, I still don't understand the danger of fetching data outside the session context. For my view components I am not intersted in transactions. Not everything has to be a transaction all the time, esspecially select statements. Can the stateless session help me out? It does not implement session so I cannot oversee the impact of it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 8:58 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
You can hack PojoTuplizer for proxies (3.1) or to use custom persister (3.0) and implement custom collection types (see unit tests and hibernate source code).
You can break transactions this way if you need, but you will need some synchronization and concurency control if your objects are shared by threads to avoid concurrent initialization and stale data(So you will lose performance anyway and it can be more expensive than to rebuild components)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 9:03 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
When your tree is a rendered static HTML, than I do not understand why you cannot dynamically fetch the trees you need.

I do not know if further investigation will be helpful, but in this case you should post more details. What data is shown, what interaction can the user do and what other data is needed in this case.

Regards sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 7:01 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
i didn't properly checked if an object is bound, after discovery of session.contains i added two checks in my code and the lazy initialization exception is not thrown anymore. My design is less crappy than i thought it was ;-) The application is very slow because an extreme amount of updates is done on every request. I only select, why are there updates? I try to debug but the pointer refuses to step in.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 10:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Updates when your just reading usually indicates your POJOS have some implementation issues, meaning hibernate sets the values but broken code modifies the wrong fields..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 9:54 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
I am trying to find out why the updates are performed but the debugger refuses to break. When I try to compile the hibernate src myself i run into problems because of missing src files. I believe it is all about org.hibernate.hql.antlr.* , where can i find those source files?

Why does the debugger not stop at break points when I attach the hibernates sources to the library jar, when i step into the code it performs a step over instead of step in. I use eclipse. In other situation where i attach source i can perfectly debug, is it because of proxies? I try to step into AbstractQueryImpl.uniqueElement( list() ).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 10:14 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Use ant to generate this stuff
Code:
antlr                  Generate ANTLR parsers.
antlr.bnf              Generate BNF diagram for HQL
antlr.regen            Regenerate all ANTLR generated code.
checkstyle             Check coding style
clean                  Cleans up build and dist directories
cleanantlr             Clean up the generated ANTLR parsers.
cleanimps              Clean imports
cleantestdb            Clean up HSQLDB test database
cloverreport           Run the tests and generate a clover report
cloverreport.html      Generate a clover report from the current clover database.
compile                Compile the Java source code
compiletest            Compile the tests
copylib                Copy jars to lib dir
copysource             Copy sources to dist dir
dist                   Build everything and package
eg                     Compile and run the simple example
extras                 Copy miscellaneous files to root dir
info                   Echo system properties
init                   Initialize the build
init.antlr             Check ANTLR dependencies.
instrument             Instrument the persistent classes
jar                    Build the distribution .jar file
javadoc                Compile the Javadoc API documentation to dist dir
junit                  Run the test suite (requires driver.jar property)
junitinstrument        Run the instrument test suite (requires driver.jar property)
junitinstrumentreport  Run instrumented tests and create JUnit report (requires driver.ja
r property)
junitreport            Run tests and create JUnit report (requires driver.jar property)
junitsingle            Run a single test suite (requires testname and jdbc.driver propert
ies)
patch                  Create a patch
perf                   Run the performance tests
refdoc                 Generate and copy reference documentation
replace                do a text search replace
splash                 Display the logo
versioncheck           Check version.properties up against lib directory


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 9:28 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
i can debug now and see that the

AbstractFlushingEventListener.flushEntities(FlushEvent event)

performs an update for every entry in source.getPersistenceContext().getEntityEntries()

TwoPhaseLoad.postHydrate and TwoPhaseLoad.addUninitializedEntity seems to add entityEntries regardless anything i am awhere of.

TwoPhaseLoad.addUninitializedEntity has the following comment

// add temp entry so that the next step is circular-reference
// safe - only needed because some types don't take proper
// advantage of two-phase-load (esp. components)

I have circular references in the problem area. I am pretty sure that i dont change values. Does somebody know why the entries are always added?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.