-->
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.  [ 1 post ] 
Author Message
 Post subject: how to write junit test for save method without transaction?
PostPosted: Tue Mar 15, 2005 12:01 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
how to write junit test for save method without transaction?

it seems test codes runs well, but it didn't save to database.

========================================
public void testSaveOrUpdate() {
try {
PigeonholeType pigeonholeType = new PigeonholeType();
pigeonholeType.setSymbol("none");
PigeonholeRule pigeonholeRule = new PigeonholeRule();
pigeonholeRule.setXtypeSymbol("SB006");
pigeonholeRule.setSize(new Integer(456));
pigeonholeRule.setPigeonholeType(pigeonholeType);
pigeonholeRuleDao.saveOrUpdate(pigeonholeRule);

} catch (Exception e) {
e.printStackTrace();
}

PigeonholeRule obj = pigeonholeRuleDao.loadByPrimaryKey("SB006");
System.out.println(obj.getSize());

Xtype xtype = xtypeDao.loadByPrimaryKey("SB006");
Iterator it = xtype.getSetOfPigeonholeRule().iterator();
while (it.hasNext()) {
PigeonholeRule pigeonholeRule = (PigeonholeRule)it.next();
System.out.println(pigeonholeRule.getPigeonholeType().getSymbol());
System.out.println(pigeonholeRule.getPigeonholeType().getTitle());
}
}

}

=========================================

public Serializable saveOrUpdate(PigeonholeRule obj)
throws DataAccessException {
Session session = null;
Transaction tx = null;
try {
session = sessionFactory.openSession();
// tx = session.beginTransaction();
session.saveOrUpdateCopy(obj);
session.flush();
// if not use transaction tx.commit();
return obj;
} catch (HibernateException he) {
try {
tx.rollback();
} catch(HibernateException hex) {
throw SessionFactoryUtils.convertHibernateAccessException(hex);
}

throw SessionFactoryUtils.convertHibernateAccessException(he);
} finally {
SessionFactoryUtils
.closeSessionIfNecessary(session, sessionFactory);
}
}

_________________
I am the creatxr of world.


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

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.