Magazine
 
Working with Entity bean using JPA
 

version=”5" xsi:schemaLocation=”http://
java.sun.com/xml/ns/javaee http://
java.sun.com/xml/ns/javaee/
application_5.xsd”>
<display-name>JPA Example</displayname>
<module>
<web>
<web-uri>book.war</web-uri>
<context-root>/book</context-root>
</web>
</module>
<module>
<ejb>book.jar</ejb>
</module>
</application>

jboss-app.xml
The jboss-app.xml file defines a class loader
for this application. It makes it simpler for EJB
3.0 to find the default EntityManager.

<jboss-app>
<loader-repository>
book:archive=book.ear
</loader-repository>
</jboss-app>

Put both files in the EntityBean\code\deploymentdescriptors\ear
directory.

persistence.xml

The persistence.xml file contains one or several persistence-unit element. Each persistence-unit defines the persistence context name, data source settings, and vendor specific properties. In this example, we are using the HSQL database that is default provided by the Jboss
AS. The hibernate property “create-drop” will automatically create & drop a table (according to the POJO class) each time when you deploy and run the application on server.

<persistence>
<persistence-unit name=”EntityBean”>
<jta-data-source>java:/DefaultDS</jtadata-
source>
<properties>
<property

 

name=”hibernate.hbm2ddl.auto”
value=”create-drop”/>
<property name=”hibernate.dialect”
value=”org.hibernate.dialect.HSQLDialect”/>
</properties>
</persistence-unit>
</persistence>

Put this files in the
EntityBean\code\deploymentdescriptors\jar
directory.

web.xml

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE web-app PUBLIC “-//Sun
Microsystems, Inc.//DTD Web Application 2.3/
/EN” “http://java.sun.com/dtd/webapp_
2_3.dtd”>
<web-app >
</web-app>


Put this file in the
Stateless\code\deploymentdescriptors\web directory.

Put all .jsp files in the Stateless\code\web directory.

Put all .java files in the Stateless\code\src directory.

(iii) Start command prompt, and go to the EntityBean\code directory. Then type the command as:

C:\ EntityBean\code>ant build.xml

The Ant tool will deploy the book.ear file to the jboss-
4.2.0.GA\server\default\deploy directory.

VI. Running the book application Open the web browser and type the following URL to run the application:

http://localhost:8080/book

Feb 2008 | Java Jazz Up |14
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF