Prev Next

Hibernate / Hibernate interview questions

Detached Criteria

The detached criteria allows you to create the query without Session. Then you can execute the search in an arbitrary session.

Using a DetachedCriteria is exactly the same as a Criteria except you can do the initial creation and setup of your query without having access to the session. When it comes time to run your query, you must convert it to an executable query with getExecutableCriteria(session).

DetachedCriteria query = DetachedCriteria.forClass(Person.class)
    .add( Property.forName("sex").eq('F') );
   
Transaction txn = session.beginTransaction();
List results = query.getExecutableCriteria(session).setMaxResults(100).list();
txn.commit();
session.close();

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Difference between save and persist. @UniqueConstraint and @Column Unique attribute. What is HQL (Hibernate Query Language)? What are the most common methods of Hibernate configuration? In a Parent-child relationship, how will you only access the columns from parent? Difference between Hibernate createCriteria, createQuery, createSQLQuery. Difference between @NotNull, @NotEmpty and @NotBlank. Different between session.get() and session.load() in Java. What is ORM ? What is hibernate? What does ORM consists of ? @Repository @Embeddable @Service @Controller Differentiate JPA and hibernate. What are the ORM levels ? Why do you need ORM tools like hibernate? core interfaces of Hibernate. Is SessionFactory a thread-safe object? What role does the SessionFactory interface play in Hibernate? Is Hibernate Session a thread-safe object? What are the different states of object in hibernate? How to make a immutable class in hibernate? Different types of association in hibernate. Is it possible to perform collection mapping with One-to-One and Many-to-One? What is lazy loading in hibernate? What is the difference between merge and update ? How do you define sequence generated primary key in hibernate? What are the Collection types in Hibernate ? What is Hibernate proxy? What are Callback interfaces? What are the types of inheritance models in Hibernate? Benefits of hibernate over JDBC? Session Interface. SessionFactory Interface. Configuration Interface. Transaction Interface. Query and Criteria Interface. What are Callback interfaces? What is POJO? Detached Criteria Advantages of Detached criteria. Explain N+1 SELECT problem in Hibernate. List the strategies to eliminate the N+1 SELECT problem in Hibernate. Explain high level architecture of Hibernate framework. How do we see hibernate generated SQL on console? Hibernate: Can a Entity Class be declared final? How to call stored procedure in Hibernate? Explain transaction management in hibernate. Difference between fetch mode and fetch type in Hibernate. What is the default fetch mode in Hibernate? What is the difference between FetchType.LAZY and FetchType.EAGER in Java Persistence API? Difference between using a @OneToMany and @ElementCollection annotation in Hibernate. Explain the features introduced in Hibernate 5. Which throws Exception when no row found: session.load vs session.get.
Show more question and Answers...

Hibernate interview questions II

Comments & Discussions