By Ramakrishna on Oct 5, 2008 in hibernate interview questions | 0 Comments
Rep)
1) If the above table has to be accessed using hibernate we must provide a seperae class to hold the values of the columns(multiple) of the primary key.(We can call this class as primary key class)
–>As part of Empaddressid,it will contain the properties such as setId,getId as partid of empno,addrno.
2) In case of table [...]
By Ramakrishna on Sep 2, 2008 in hibernate interview questions | 0 Comments
Q) How to create Session and SessionFactory in Hibernate?
A)
Step 1> Put Hibernate properties in the classpath.
Step 2> Put .hbm.xml in class path ?
Code is Here to create session …
package com.dao;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
*
* @author Satya Das
*/
public class HibernateUtil {
protected static final Logger
logger=Logger.getLogger(HibernateUtil.class);
public static String appHome = “No”;
private static SessionFactory [...]
By Ramakrishna on Sep 2, 2008 in hibernate interview questions | 0 Comments
Q.Difference between getCurrentSession() and openSession() in Hibernate ?
A)
getCurrentSession() :
The “current session” refers to a Hibernate Session bound by Hibernate behind the scenes, to the transaction scope.
A Session is opened when getCurrentSession() is called for the first time and closed when the transaction ends.
It is also flushed automatically before the transaction commits. You can call [...]
By Ramakrishna on Sep 2, 2008 in hibernate interview questions | 0 Comments
Q) Difference between session.update() and session.lock() in Hibernate ?
A) Both of these methods and saveOrUpdate() method are intended for reattaching a detached object.
The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object.
It is the best practice to [...]