Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
| ||||
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   proxy objects   proxy classes   entity hibernate | ||||
| ||||
Ans. JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  jpa   hibernate   orm   architecture   technologies Asked in 2 Companies | ||||
| ||||
Ans. Its a specification that guides the implementation of ORM frameworks. Implementations abiding by the specification would mean that one can be replaced with other in an application without much hassle. Only the Features that are added over the specification needs to be taken care of if any such change is made. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  jpa   hibernate   orm   technologies | ||||
| ||||
Ans. Criteria is a simplified API for retrieving entities by composing Criterion objects. For example - session.createCriteria(Employee.class).add( Restrictions.like("name", "A%") ).list(); will return all employee objects having name starting with A. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria Asked in 7 Companies Basic   Frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. The following code returns the list of Employee objects having employee name starting with A and Dept Name ( Department , Employee Mapped ). session.createCriteria(Employee.class,"emp") .createAlias("emp.department", "dept",Criteria.INNER_JOIN) .add( Restrictions.like("name", "A%") ) .add(Restrictions.eq("dept.name","Finance") .list(); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   hibernate table mapping | ||||
| ||||
Ans. eq, ge, gt , between, in , isNull, isEmpty, isNotnull, ne , like, lt , or , not | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   hibernate restriction | ||||
| ||||
Ans. Yes, with Enum as was getting an exception while doing equality check for enum field. got it fixed by adding @Enumerated(EnumType.STRING) to the field in entity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   enumerations | ||||
| ||||
Ans. I prefer using Criteria for Dynamic queries and HQL for static queries. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   hql | ||||
| ||||
Ans. session.createCriteria(Employee.class).add( Restrictions.or(Restrictions.like("name", "A%"),Restrictions.like("name", "B%"))).list(); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate  Criteria  Restrictions | ||||
| ||||
Ans. JDBC is a standard Java Api for Database communication whereas Hibernate is an ORM framework that uses JDBC to connect with Database. Hibernate is another layer of object table mapping over JDBC that provide a database independent, object oriented and an efficient way of database communication. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  JDBC  Hibernate  JDBC vs Hibernate Asked in 3 Companies | ||||
| ||||
Ans. No, Every entity in hibernate needs to have a key, either primary or composite. If we dont have a primary key on table, there are various ways this problem can be countered. 1. By using composite key on entity ( make sure that the appropriate unique constraint in defined on columns in Database ) 2. By mapping Id in entity to ROWID of table. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate entity  hibernate | ||||
| ||||
Ans. // Non-managed environment idiom Session sess = factory.openSession(); Transaction tx = null; try { tx = sess.beginTransaction(); // do some work ... tx.commit(); } catch (RuntimeException e) { if (tx != null) tx.rollback(); throw e; // or display error message } finally { sess.close(); } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   Asked in 1 Companies | ||||
| ||||
Ans. Make sure that the properties of dependent Hibernate entities are not accessed and if yes, better wrap the whole code within single transaction. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  lazy loading  lazy initialization | ||||
| ||||
Ans. Lazy Initialization means , Load Dependencies when required. Which means less load on application resources as only required data is loaded upfront. It's not only good for better performance but for better resource utilization too. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  lazy loading  lazy initialization   frequent | ||||
| ||||
Ans. Save is used to save the entity to the session whereas flush is to save the session content to DB. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. It specifies an association fetching strategy. It could be DEFAULT, JOIN or SELECT as following @Fetch(FetchMode.SELECT) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. JDBC ( Java Database Connectivity ),ODBC (Open Database Connectivity), Hibernate, JPA ( Java Persistence API ), JOOQ,MyBatis | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  database connection  jdbc  ORM  Hibernate Asked in 1 Companies | ||||
| ||||
Ans. No, it's not legal in hibernate. 1 column should be mapped to only one field in entity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. We can use @AccessType("property") for getDepartmentId() method within Department class in that case. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. a | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Lazy Loading  Lazy Initialization  org.hibernate.LazyInitializationException | ||||
| ||||
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping. third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished. I don't mind using 4th too. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  lazy loading  lazy initialization  LazyInitializationException | ||||
| ||||
Ans. Lazy Initialization exceptions | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. No. It's a resource and performance overhead. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  LazyInitializationException  Lazy Loading | ||||
| ||||
Ans. Yes, the feature is there but can be override with changing the Flush Mode. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
Ans. If it's only a read only transaction, we can wrap the get / load call in read only transaction. If we want it to be application wide, we an set the flush mode accordingly or else we can evict the entity object to remove them from session. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. session.clear clears all the objects from session whereas session.evict is used for evicting a particular entity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate session clear  hibernate evict | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. It is used to clear the session and is used to dissociate disconnect all the objects from the session. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate session clear | ||||
| ||||
Ans. It is used to dissociate / disconnect a particular object from the session. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate session evict  hibernate evict | ||||
| ||||
Ans. Session,SessionFactory,Configuration,Transaction,query and Criteria | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  core interfaces of Hibernate Asked in 1 Companies   frequent | ||||
Try 1 Question(s) Test | ||||