[jboss-user] [EJB 3.0] - Re: How to get this (very simple) tutorial to work in JBoss

Hellek do-not-reply at jboss.com
Thu May 17 11:55:11 EDT 2007


I also found this (yesterday already) http://forum.java.sun.com/thread.jspa?threadID=5162297&tstart=60
but I just don't understand it.

They all have interfaces etc. and in the tutorial I tried to follow, they don't have such things at all.

In the tutorial they have:
1.) An EJB-Project with the persistence.xml and a Bean. The bean is just a "copy" of an existing table with getters and setters for all columns and the @Entity and @Id Annotations.
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
  | <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  | 	<persistence-unit name="EJBProject1">
  | 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
  |     	<jta-data-source>java:/TestDS</jta-data-source>
  | 		<class>com.Benutzer</class>
  | 		<properties>
  | 		  <property name="hibernate.dialect"
  | 				value="org.hibernate.dialect.MySQLDialect" />
  | 		  <property name="hibernate.transaction.manager_lookup_class" 
  |             value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
  | 		  <property name="hibernate.hbm2ddl.auto" value="update"/>
  | 		</properties>
  | 	</persistence-unit>
  | </persistence>

The datasource works fine, i.e. hibernate succesfully updates the table if I mess it up.

2.) A WebProject
With a servlet which looks like this:

  | public class Servlet1 extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
  | 
  | public Servlet1() {
  | 		super();
  | }
  | 
  | @PersistenceUnit(name="EJBProject1")
  | EntityManagerFactory emf;
  | 
  | /* (non-Java-doc)
  | * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  | */
  | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  | response.setContentType("text/html"); 
  | response.setHeader("Pragma", "No-cache");
  | response.setDateHeader("Expires", 0);
  | response.setHeader("Cache-Control", "no-cache");
  | 
  | List users = emf.createEntityManager().createQuery("select b from Benutzer b").getResultList();
  | PrintWriter writer = response.getWriter();
  | 
  | for (Iterator iterator = users.iterator(); iterator.hasNext();) {
  | 			 Benutzer benutzer = (Benutzer) iterator.next();
  | 			 writer.print(benutzer.getName());
  | 		 }
  | 		 writer.flush();
  | writer.flush();
  | } 
  | }
  | 

and a plain normal web.xml that just maps Servlet1 to an url

3.) Those 2 projects are then combined into an EARProject. Result is a .EAR-File with a jar for the Bean and a war for the webproject inside and the following application.xml
<?xml version="1.0" encoding="UTF-8"?>
  | <application id="Application_ID" version="5.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_5_0.xsd">
  | 	<display-name>
  | 	EARProject1</display-name>
  | 	<module>
  | 		<web>
  | 			<web-uri>WebProject2.war</web-uri>
  | 			<context-root>WebProject2</context-root>
  | 		</web>
  | 	</module>
  | 	<module>
  | 		<ejb>EJBProject1.jar</ejb>
  | 	</module>
  | </application>

All 3 projects have a MANIFEST.MF that just says

  | Manifest-Version: 1.0
  | Class-Path: 
  | 

I hope this illustrates the content very well, unfortunately I don't understand how to apply what people say in those topics about JNDI etc. onto this structure.

It would really be great if somebody could tell me how to do it.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046539#4046539

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046539



More information about the jboss-user mailing list