public static final String HIBERNATE_HOTEL_ADDRESS = "Hibernate Address";
private TransactionTemplate hibernateTransactionTemplate;
public void testHibernateIntegration() {
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through HibernateTemplate
Hotel hotel = (Hotel)getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException {
return getFirstHotel(session);
}
});
hotel.setName(HIBERNATE_HOTEL_NAME);
return null;
}
});
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through SessionFactory.getCurrentSession()
Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
if (!HIBERNATE_HOTEL_NAME.equals(hotel.getName())) {
throw new RuntimeException("Hotel name not set. Hibernate integration not working.");
}
hotel.setAddress(HIBERNATE_HOTEL_ADDRESS);
return null;
}
});
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through SessionFactory.getCurrentSession()
Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
if (!HIBERNATE_HOTEL_ADDRESS.equals(hotel.getAddress())) {
throw new RuntimeException("Hotel address not set. Hibernate integration not working.");