Hi, recently bought the manning book and read myself up to a beginner level on hibernate as Im using it to implement a persistent domain model for a customer. I've got previous experience with EJB 2.x Enitity beans and CRM/CMP and found a lot of similarities...
My application will be a struts/JSP application that works as an admin interface to data in an Oracle database. Im using a Oracle 10g Application server as well.
I really want to use CMT. (Container managed transactions), and declarative transaction demaraction.
0. Is the "simple" HibernateUtil (from Caveatemptor) most suitable for J2EE/EJB settings? Is keeping the session in a thread local variable suitable for Container code ?
1. How do I write business code that can run in the container, and be
tested in a "local" test harness using HSQLDB / Junit ? The container code does currently *Not* use the Hibernate transaction API (explicit commit/rollback). My Business objects look like this ;
public void someBusinessmethod() {
Session session = sessions.currentSession() ;
session.saveOrUpdate(...)
}
No flush, no commit, no rollback. All handled by the container/JTA. However, when unit testing my Business method, I run the test on my local computer and have no container. How can one solve this issue?
Some DAO/BO design pattern might solve this, any best practices ?
I don't want (and are not paid) to re-invent any wheels here.
2. I also use plan on using the (anti) pattern session-per-request, meaning that an http request hits the servlet engine (for example the first page of the application).
1. The servlet requests data from the EJB session facade
2. A hibernate sessoion is started
3. Data is fetched
4. Session is closed
5. Data is returned
6. Data displayed in the web GUI.
Is this considered bad ? don't really see any point of using "application transactions" in my case.
Some insight, and real life experience would be most welcome !
Best regards a and happy hollidays to all of you.
|