34 lines
769 B
Java
Raw Normal View History

2015-04-15 21:45:14 +03:00
package com.iluwatar.spell;
2015-04-13 22:36:52 +03:00
2015-04-15 21:11:12 +03:00
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Expression;
2015-04-15 21:45:14 +03:00
import com.iluwatar.common.DaoBaseImpl;
2015-04-14 23:38:50 +03:00
public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
2015-04-13 22:36:52 +03:00
2015-04-15 21:11:12 +03:00
@Override
public Spell findByName(String name) {
Session session = getSession();
Transaction tx = null;
Spell result = null;
try {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
criteria.add(Expression.eq("name", name));
result = (Spell) criteria.uniqueResult();
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
session.close();
}
return result;
}
2015-04-13 22:36:52 +03:00
}