http://www.oracle.com/technetwork/articles/cioroianu-eclipse-jpa-084626.html
1.create Eclipse Web project testWeb
2.create Servlet calling Session EJB
package dave;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TestJPAServlet
*/
public class TestJPAServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TestJPAServlet() {
super();
// TODO Auto-generated constructor stub
}
@EJB
SessionJPA2EJBRemote remoteBusinessIntf;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String nameParam = request.getParameter("emp");
Author author = remoteBusinessIntf.findAuthorByName(nameParam);
System.out.println("author " + author);
PrintWriter out = response.getWriter();
out.println("author" + author);
// Books
Set<Book> books = author.getBooks();
for (Book book : books) {
System.out.println("book " + book);
out.println("book" + book);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
3. call servlet using URL composed of testWeb project and Servlet
http://localhost:7001/testWeb/TestJPAServlet?name=dave
[EL Finest]: 2011-02-20 15:15:14.763--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--End deploying Persistence Unit books; session file:/home/dave/workspace/wls1033/testJPA2/build/classes/_books; state Deployed; factoryCount 1
[EL Finer]: 2011-02-20 15:15:14.763--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client acquired
[EL Finer]: 2011-02-20 15:15:14.763--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finest]: 2011-02-20 15:15:14.764--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(referenceClass=Author sql="SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)")
[EL Finest]: 2011-02-20 15:15:14.764--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2011-02-20 15:15:14.765--ServerSession(10406216)--Connection(3587614)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)
bind => [1]
[EL Finer]: 2011-02-20 15:15:14.767--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2011-02-20 15:15:14.767--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--begin unit of work commit
[EL Finer]: 2011-02-20 15:15:14.768--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2011-02-20 15:15:14.769--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--end unit of work commit
[EL Finer]: 2011-02-20 15:15:14.769--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--release unit of work
[EL Finer]: 2011-02-20 15:15:14.769--ClientSession(26961217)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client released
author dave.Author@1fbc274
[EL Finest]: 2011-02-20 15:15:14.77--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadAllQuery(name="books" referenceClass=Book )
[EL Finest]: 2011-02-20 15:15:14.77--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2011-02-20 15:15:14.771--ServerSession(10406216)--Connection(11941411)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, TITLE, COUNTER, INSERT_TIMESTAMP, AUTHOR_ID FROM BOOK WHERE (AUTHOR_ID = ?)
bind => [1]
[EL Finest]: 2011-02-20 15:15:14.773--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(name="author" referenceClass=Author )
[EL Finest]: 2011-02-20 15:15:14.774--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Register the existing object dave.Book@9c71bf
book dave.Book@9c71bf
No comments:
Post a Comment