File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Loading DAO and SQL on demand for the request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Loading DAO and SQL on demand for the request" Watch "Loading DAO and SQL on demand for the request" New topic
Author

Loading DAO and SQL on demand for the request

Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Hi,

I have a requirement, where I need to load the SQL queries for the specific DAO on demand when the request has been made. This will ensure that I am not loading all the objects as I will be loading only the objects which I am going to work with. That is the main idea behind this operation. I am using JPA for back-end which connects to Oracle DB. Whether it will be better to load all the module specific DAO's on-demand using lazy-init="true" in Spring and load the specific SQL queries for those DAO's? In hibernate we are using named queries. Hence, please do suggest me how we can go about this?
Whether it is better to load the DAOImpl and specific SQL for those DAO on demand (lazy-init="true")?If that is the case how we can do it? Please give me some examples on this? Whether we need to configure the named SQL queries in text file or XML? Which one will be better.Also suggest me which will be the best way of handling this? Any ideas are really appreciated.

Thanks.
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Does your application have 2 database connections ? Are you using hibernate jpa ?
Are your native sql queries complex ? is it not possible to apply associations ( one to many relationships etc) in your application ?

Even if you've loaded the queries in a separate file, they must get executed at some point of time. This brings back to the same point, when should the queries be executed and when should the objects be loaded. The goal is to load objects lazily, its a must do job after the entities and entity relationships have been generated. Primarily its dependent on the functional aspects and data size in a request session scope. Hibernate provides some strategies to improve performance.


Thanks,
Tushar (SCJP 1.5)
Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Thanks Mishra, We have only one DB connection Oracle. We have 75 % of native SQL queries which needs to be loaded when the respective DAO gets loaded either eagerly of lazily. The thing here is we will load the entity class as well as the respective .hbm.xml files eagerly when we load our dataAccess.xml file of Spring which contains all the .hbm.xml referenced. Hence that is not a problem. The problem here is
loading the DAO objects. Let say that i am working in a module A where I dont need the Module B & C to be loaded. hence on demand I will load only my module related DAO objects and wont load the
Module B & C DAO objects. As I don't need them as their is no dependency. How we can achieve this using spring or from hibernate side? Please clarify.
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Does your native sql query have multiple levels of joins ?
Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Yes Mishra, I am joining up to 5 tables using native SQL? Please suggest me a solution for this?
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Most of the configuration I can think of is limited to lazy load during application startup. That is, the file loading is a one time activity at application statup using Configuration#addCacheableFile. But this does not fit into your requirement. If I understand correcly, you want to load named queries for the daos based on request. I am still looking into the solution. But i think its better to take suggestions from Bartenders / Marshals or an expert.

Edit - Named query loading on demand, Temporary solution to improve hibernate startup, example
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

The thing here is we will load the entity class as well as the respective .hbm.xml files eagerly when we load our dataAccess.xml file of Spring which contains all the .hbm.xml referenced.
. Looks like you've already externalized queries.. I think, you can load named queries of the respective dao when needed using this approach.
Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Mishra, I am already using the named queries , but how i can load those .hbm.xml with named queries on demand based on the request that has been serviced as these .hbm.xml are configured under mapping resources of hibernate.cfg.xml
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading DAO and SQL on demand for the request