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.
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.
Tushar (SCJP 1.5)
posted 6 years ago
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.
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.
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.
Tushar (SCJP 1.5)
posted 6 years ago
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
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad: