sujitmishra wrote:
Hi,
Whenever we are trying to insert a record in sql serverl table through java method using hibernate, it locks the table and didnot retrive the data. The flow is as follows:
public String addRole(String codeHier,String psOrgLvl,String psOrgLvlCode,String idnEntprsRole,String idnUpdtUser){
int roleId = 0;
Session session = HibernateUtil.currentSession();
String msg = "false";
try{
if(idnEntprsRole!=null)
roleId=Integer.parseInt(idnEntprsRole);
HibernateUtil.beginTransaction();
if(!isCodeCmpntMbr(codeHier,psOrgLvl,psOrgLvlCode, session))//Record Not in Code Component Member Table
{
insertCodeComponentMbr(codeHier,psOrgLvl,psOrgLvlCode,idnUpdtUser,session);
insertComponentEntprsRole(codeHier,psOrgLvl,psOrgLvlCode,roleId,idnUpdtUser,session);
msg = "true";
}
else
{
if(!isCompEntprsRole(codeHier,psOrgLvl,psOrgLvlCode,roleId, session))
{//Record Not in Component Enterprise Role Table
insertComponentEntprsRole(codeHier,psOrgLvl,psOrgLvlCode,roleId,idnUpdtUser,session);
msg = "true";
}
else
msg ="false";
}
HibernateUtil.commitTransaction();
}catch (HibernateException ex) {
HibernateUtil.rollbackTransaction();
logger.error(ex.getMessage());
ex.printStackTrace();
//throw new RuntimeException(e.getMessage());
} catch(Exception e){
HibernateUtil.rollbackTransaction();
logger.error(e.getMessage());
e.printStackTrace();
}finally{
if(session != null){
session.flush();
HibernateUtil.closeSession();
}
}
return msg;
}
-------------------------------------------------
private void insertComponentEntprsRole(String codeHier,String psOrgLvl,String psOrgLvlCode,int idnEntprsRole,String idnUpdtUser,Session session)throws HibernateException, Exception{
logger.info("Method entrance" + MSDateUtil.getDateTimeStamp());
Date currentDate = MSDateUtil.getcurrentDate();
TcmpntNtrprsRole cnr = new TcmpntNtrprsRole();
TcmpntNtrprsRoleId cnrId = new TcmpntNtrprsRoleId();
cnrId.setCdeHier(codeHier);
cnrId.setCdeCmpnt(psOrgLvl);
cnrId.setCdeCmpntMbr(psOrgLvlCode);
cnrId.setIdnEntrprsRole(idnEntprsRole);
cnr.setId(cnrId);
cnr.setIdnUpdtUser(idnUpdtUser);
cnr.setTmsUpdt(currentDate);
session.saveOrUpdate(cnr);
logger.info("Method exit" + MSDateUtil.getDateTimeStamp());
}
------------------------------
For more info please find below::
Hibernate - hibernate-3.2.4.sp1
Websphere - WAS 5.1
MS SqlServer - 2000
Sql Sever Driver 2005 i.e. com.microsoft.jdbc.sqlserver.SQLServerDriver
Also copy the following from hibernate.cfg.xml <session-factory name="java:hibernate/SessionFactory">
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.cache.region_prefix">
hibernate.test
</property>
<property
name="connection.datasource">jdbc/XXX</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.substitutions">
true 1, false 0, yes 'Y', no 'N'
</property>
Database Trace Showed - That for the above select/insert (thread 1 of
blog) the selects are opening cursor and not closing the cursor even thought there is open & close cursor commands which is not allowing insert to proceed. We have flush tried with and with out flush within our transaction. Our session & transactions are separate threads in hibernateUtil.
Please let us know if there will be any soultion for this.....