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;
| }
At the DAO level there is an inner class that has the following:
|
| 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();
| }
This finally made it work where the updates and deletes were commited. I had
to explicitly call s.setFlushMode(FlushMode.AUTO); and s.flush() to ensure that
everything works.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3879061#3879061
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3879061
-------------------------------------------------------
SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
online with coworkers and clients while avoiding the high cost of travel and
communications. There is no equipment to buy and you can meet as often as
you want. Try it free.http://ads.osdn.com/?ad_id=7402&alloc_id=16135&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user