Mar 19th, 2007, 11:52 AM
What's the best way to use the objects loaded by Hibernate?
Let's say that I received parameters from the UI in order to apply my criteria in the database. After load my objects, I have to use these information through the system, without hit the database again with the selects. What's the best way to save this kind of information in the memory? I know how to use the POJO, DAO etc, but is there any special technique for that using Spring?
Mar 19th, 2007, 01:18 PM
It sounds like your saying the one fetch has to return all the data in one go. In that case you just need to eagerly the association data. If you are using caching as well, this stops you hitting the database.
#1. Set assocation lazy=false (wouldn't do that unless its the only option)
#2. Eagerly load in HQL or Criteria API
#3. Use HibernateTemplate.initialize()
#4. Walk the association inside the session (i.e. collection.size())
Mar 19th, 2007, 01:28 PM
It's helpful the links you are providing. However, I need to know how to hold the information using Spring as well . I know they are related and I should already know some concepts that I am studying right now, but last weekend I struggled with an error that I couldn't fix and now I am here again trying to delivery something this week to my boss. Do you have any example that would answer my question? Sorry about the emergency.
Mar 19th, 2007, 01:31 PM
It's hard to answer the question as I'm not really sure what you are after here. You can to store the state somewhere? You could use a Session/Request scoped bean. It all depends on what you are trying to do here.
Mar 19th, 2007, 01:42 PM
No web requests up to now. I am handling only the service layer with its business logic accessing the DAOs. What I could do is to use the object loaded as a parameter to its interface and all the class that implements this interface would recognize the object. I already saw that in a bunch of examples and it's a pretty simple way to do the things, I just have my thoughts flying sometimes. So, I believe that's better I try this approach right now and if I have any issue I will post here. Thanks.
Mar 19th, 2007, 03:31 PM
I'm not sure what you are getting at, but as long as you understand it .