These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem while insert record in table through hibernate trans
PostPosted: Thu Jun 28, 2007 9:51 am 
Newbie

Joined: Thu Jun 28, 2007 9:39 am
Posts: 9
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());
}
------------------------------
Please let us know if there will be any soultion for this.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 12:26 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
What flush mode are you using? You might have to flush your session before you commit your transaction. Flushing actually fires the SQL to the database so if you aren't flushing before commit your changes won't be seen.

Try turning on show sql in the hibernate config and step through your code. By the time the commit completes you should see the insert sql fly by. If not, then you will either need to change your flushing strategy or flush the session youself.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 1:04 am 
Newbie

Joined: Thu Jun 28, 2007 9:39 am
Posts: 9
generally we are doing session.flush(); before commiting...


Top
 Profile  
 
 Post subject: Re: Problem while insert record in table through hibernate t
PostPosted: Fri Jun 29, 2007 6:51 am 
Newbie

Joined: Thu Jun 28, 2007 9:39 am
Posts: 9
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.....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.