Posts

Showing posts with the label Hibernate

Hibernate 'hql' does not support UNION - Hibernate

So in this case run each query individually using 'HQL' and then add the results to a HashSet

Criteria - Hibernate

In Hibernate, the Criteria API helps us build criteria query objects dynamically. Criteria is a another technique of data retrieval apart from HQL and native SQL queries. The primary advantage of the Criteria API is that it is intuitively designed to manipulate data without using any hard-coded SQL statements. Programmatic behavior offers compile-time syntax checking; as a result, most error messages are delivered during compilation. Although it's convenient, this does not provide any performance enhancing ability over HQL or native SQL queries. In fact, it's a preference given to developers to choose according to taste and necessity. You may use all three or stick to one. Let's see if we can find some examples to appreciate the Criteria Query API. Getting Started The  org.hibernate.Criteria  interface defines several methods for creating query objects programmatically. We generally use a  Session  object to call the  createCriteria()  method and crea...

Session Factory scope - Hibernate - Java

Session factory objects are to be implemented using the  singleton  design pattern. Instances of SessionFactory are  thread-safe  and typically shared throughout an application. As these objects are heavy weight because they contains the connection information, hibernate configuration information and mapping files,location path. So creating number of instances will make our application  heavy weight . But the session objects are not thread safe. So in short it is - SessionFactory objects are one per application and Session objects are one per client. Hence it would be one SessionFactory per DataSource. Your application may have more than one DataSource so you may have more than one SessionFactory in that instance. But you would not want to create a SessionFactory more than once in an application. Advantages : Obviously its improving performance of your application :) UPDATE - Extract from  Hibernate Doc The internal state of a SessionFactory is i...