This is to inform anyone that was having difficulty getting Hibernate 3 to work with JBoss 4.02 with EJB Preview 5.
The following needs to be done at the EJB Layer:
@Unchecked
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Employee login() {
EmployeeLogonDAO eldao = new EmployeeLogonDAO();
Employee emp = getEmployee();
try {
if (emp != null) {
//Log the employee
EmployeeLogon elogon = new EmployeeLogon();
elogon.setEmployeeID(emp);
elogon.setLogontime(new Date());
eldao.save(elogon);
}
}
catch (Exception e) {
log.error(e.getMessage());
}
return emp;
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession()
throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
try {
SessionFactory sf = (SessionFactory) new InitialContext().lookup("java:hibernate/HibernateFactory");
s = sf.openSession();
s.setFlushMode(FlushMode.AUTO);
session.set(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
s.flush();
session.set(null);
if (s != null) s.close();
}