Hi,
This is the code I use to retrieve records.
public static ArrayList getFluClinicFamily( String enteredBy )
{
ArrayList fluFamilyList = new ArrayList( );
try
{
Session session = HibernateUtil.getSession( Constants.UDB_DATABASE );
StringBuffer sql = new StringBuffer( "from FluClinic as fluClinic " );
sql.append( "where fluClinic.enteredBy = :enteredBy " );
sql.append( "order by fluClinic.enterTimeStamp desc " );
Query query = session.createQuery( sql.toString( ) );
query.setParameter( "enteredBy", enteredBy );
fluFamilyList = (ArrayList) query.list( );
} catch( HibernateException e )
{
paslog.error( e );
return null;
}
return fluFamilyList;
}
I select certain records for update using the following code.
public static ArrayList getFluClinicByTimeStamp( String enterTimeStamp, String enteredBy )
{
ArrayList fluClinicByTimeStampList = new ArrayList( );
try
{
Session session = HibernateUtil.getSession( Constants.UDB_DATABASE );
StringBuffer sql = new StringBuffer( "from FluClinic as fluClinic " );
sql.append( "where fluClinic.enterTimeStamp = :enterTimeStamp " );
sql.append( "and fluClinic.enteredBy = :enteredBy " );
sql.append( "and fluClinic.transactionStatus not in ('D','U','C') " );
Query query = session.createQuery( sql.toString( ) );
query.setParameter( "enterTimeStamp", enterTimeStamp );
query.setParameter( "enteredBy", enteredBy );
fluClinicByTimeStampList = (ArrayList) query.list( );
} catch( HibernateException e )
{
paslog.error( e );
return null;
}
return fluClinicByTimeStampList;
}
And this the actual code I use for updating the records.
public static boolean updateFluClinic( FluClinic fluClinic, FluClinicPK pk )
{
try
{
HibernateUtil.beginTransaction( Constants.UDB_DATABASE );
Session session = HibernateUtil.getSession( Constants.UDB_DATABASE );
FluClinic flu = (FluClinic) session.get( FluClinic.class, pk );
combineProperties(fluClinic, flu);// this copies the fluClinic properties to flu properties.
session.merge( flu);
HibernateUtil.commitTransaction( );
return true;
} catch( HibernateException e )
{
HibernateUtil.rollbackTransaction( );
paslog.error( e.getMessage( ) );
return false;
}
}
I get a deadlock after one round trip. What could be the reasons? this is a part of the application and the Mapping works fine for the main application.
Thanks,
Nithya.
|