|
Maven2 with JPA Example |
|
newTx.commit();
newEm.close();
// Shutting down the application
emf.close();
}}
This example does not refer to any
persistent framework directly. Instead, it
uses symbolic names to access the
framework in indirect way. In the above
mentioned example we have used
"helloworld" name to refer to the ORM
framework.
3. In this example we used Hibernate
(http://hibernate.org) as persistence
framework and hsqldb (http://hsqldb.org)
as database. Let's take a look at the
hibernate configuration file
(persistence.xml) where we describe
"helloworld" factory:
persistence.xml
<persistence 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"
version="1.0">
<!-- persistence.xml -->
<persistence-unit name="helloworld">
<!-- The provider only needs to be set if
you use several JPA providers -->
<provider>
org.hibernate.ejb.HibernatePersistence
</provider>
<properties>
<!-- Scan for annotated classes and
Hibernate mapping XML files -->
<property
name="hibernate.archive.autodetection"
value="class, hbm"/> |
|
<!-- SQL stdout logging -->
<property name="hibernate.show_sql"
value="true"/>
<property name="hibernate.format_sql"
value="true"/>
<property name="use_sql_comments"
value="true"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.
HSQLDialect"/>
<property
name="hibernate.connection.
driver_class"
value="org.hsqldb.jdbcDriver"/>
<property
name="hibernate.connection.url"
value="jdbc:hsqldb:file:persistence-db/
test"/>
<property
name="hibernate.connection.
username"
value="sa"/>
<property
name="hibernate.hbm2ddl.auto"
value="create"/>
<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property
name="hibernate.c3p0.
max_statements"
value="50"/>
<property
name="hibernate.c3p0.
idle_test_period"
value="3000"/>
</properties>
</persistence-unit>
</persistence>
persistence.xml should be located on your
CLASSPATH within META-INF directory. "hibernate.hbm2ddl.auto" property will
take care of creating database table
automatically.
4. Create a Maven2 file i.e. pom.xml file,
responsible for downloading all dependent
libraries, building correct CLASSPATH for the
project and running the example. POM is the
fundamental unit of work in Maven. It is an
xml file that contains information about the
Download Maven2JPA Source Code |
|
Sept 2007 | Java Jazz Up |37
|
|
|
|
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,
73,
74,
75,
76,
77,
78,
79, Download PDF |
|
|
|
|
|
|
|
|
|