• +91 9723535972
  • info@interviewmaterial.com

Hibernate Interview Questions and Answers

Hibernate Interview Questions and Answers

Question - 21 : - How can I order by the size of a collection?

Answer - 21 : - Use a left join, together with group by select user from User userleft join user.messages msggroup by user order by count(msg)

Question - 22 : - How can I query for entities with empty collections?

Answer - 22 : - from Box boxwhere box.balls is empty Or, try this: select boxfrom Box box   left join box.balls ballwhere ball is null

Question - 23 : - How can I sort / order collection elements?

Answer - 23 : - There are three different approaches: 1. Use a SortedSet or SortedMap, specifying a comparator class in the sort attribute or or . This solution does a sort in memory. 2. Specify an order-by attribute of , or , naming a list of table columns to sort by. This solution works only in JDK 1.4+. 3. Use a filter session.createFilter( collection, "order by ...." ).list()  

Question - 24 : - Are collections pageable?

Answer - 24 : - Query q = s.createFilter( collection, "" ); // the trivial filterq.setMaxResults(PAGE_SIZE);q.setFirstResult(PAGE_SIZE * pageNumber);List page = q.list();

Question - 25 : - I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?

Answer - 25 : -      parent

Question - 26 : - How can I bind a dynamic list of values into an in query expression?

Answer - 26 : - Query q = s.createQuery("from foo in class Foo where foo.id in (:id_list)");q.setParameterList("id_list", fooIdList);List foos = q.list();

Question - 27 : - Can I map an inner class?

Answer - 27 : - You may persist any static inner class. You should specify the class name using the standard form ie. eg.Foo$Bar

Question - 28 : - How can I assign a default value to a property when the database column is null?

Answer - 28 : - Use a UserType.

Question - 29 : - How can I trucate String data?

Answer - 29 : - Use a UserType.

Question - 30 : - How can I trim spaces from String data persisted to a CHAR column?

Answer - 30 : - Use a UserType.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners