I faced a really big problem with creating database using persistent.xml . Ok, i start from the beginning.
I created a maven (artifact ->webapp) project. I added a META-INF directory with file persistence.xml into my source directory like that:
<?xml version="1.0" encoding="UTF-8"?>
<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_2_0.xsd"
version="2.0">
<persistence-unit name="myDatabase" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/Lab6" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence>
Then i put some model into my java sources. I added apropiate annotations like that:
package model;
import javax.persistence.*;
#Entity
#Table(name="author")
public class Author
{
private int Id;
private String firstName;
private String lastName;
#Id
#Column(name = "id", nullable = false)
#GeneratedValue(strategy= GenerationType.SEQUENCE, generator="seq")
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
#Column(name = "first_name", nullable = false)
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Column(name = "last_name", nullable = false)
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
After this I added a servlet class to connect to let the program make some operations using POST method. Nevermind :) After that I run the project and ... nothing hapened; program run successfully, I can get into servlet but database hadnt been created. Then I started to search the solution on a web and nothing helped my with my problem. Below is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Lab6</groupId>
<artifactId>Lab6</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Lab6 Maven Webapp</name>
<url>http://maven.apache.org</url>
<build>
<finalName>Lab6</finalName>
<testResources>
<testResource>
<directory>src/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>net.java.dev.glassfish</groupId>
<artifactId>glassfish-persistence-api</artifactId>
<version>b32g</version>
</dependency>
</dependencies>
</project>
I really stuck. Until now i checked other versions of providers (eclipse) in persistence.xml, and made some really weird changes inside that file but without success. I was checking also war file. Every needed file were inside (especcially persistence.xml). FI change my current glassfish version of server to different ones but it didnt help :(((
Reeally guys please help me with that. My knowlage is ropably too low to have better ideas ghow to fix that
Thanks in advance
You are missing the part of persistence.xml that tells it how to find your classes. Here are a couple options:
<jar-file>MyLibrary.jar</jar-file>
<class>model.Author</class>
Which option you choose will depend on how your project is set up.
Related
I have my persistence.xml with the same name, using toplink, under META-INF directory. Then I have my code calling it with...
public class DBConnect {
#PersistenceUnit
EntityManagerFactory emf;
public DBConnect()
{
emf = null;
}
public void startConnection()
{
emf = Persistence.createEntityManagerFactory
(
"cvut.fel.pjv.persistence.xml"
);
}
public void closeConnection()
{
emf.close();
}
public EntityManagerFactory getEMF()
{
return emf;
}
}
I have got the following error message:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named cvut.fel.pjv.persistence.xml
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at utils.DBConnect.startConnection(DBConnect.java:30)
at utils.Server.<init>(Server.java:32)
at utils.Server.main(Server.java:58)
Here are my persistence.xml - I think it should be right
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="cvut.fel.pjv_LibrarySystem_server_jar_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.Vydani</class>
<class>model.Nosic</class>
<class>model.Vypujcka</class>
<class>model.Adresa</class>
<class>model.Casopis</class>
<class>model.Kategorie</class>
<class>model.Kniha</class>
<class>model.Nakladatelstvi</class>
<class>model.Zamestnanec</class>
<class>model.Ctenar</class>
<class>model.Vytisk</class>
<class>model.Autor</class>
<class>model.SpisovatelePocetDel</class>
<class>model.UzivateleAdresy</class>
<class>model.Osoba</class>
<class>model.DigitalniNosic</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://slon.felk.cvut.cz:5432/db18_koresmi1"/>
<property name="javax.persistence.jdbc.user" value="db18_koresmi1"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.password" value="Hk2JsA"/>
</properties>
</persistence-unit>
</persistence>
And there is a pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cvut.fel.pjv</groupId>
<artifactId>LibrarySystem_server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
I very much appreciate your help - I'm doing in netbeans as a maven project
The argument for Persistence.createEntityManagerFactory is the name of the persistence unit. According to your persistence.xml your persistence unit is named cvut.fel.pjv_LibrarySystem_server_jar_1.0-SNAPSHOTPU. The following code should work:
emf = Persistence.createEntityManagerFactory("cvut.fel.pjv_LibrarySystem_server_jar_1.0-SNAPSHOTPU");
I am able to retrieve and persist an Entity without listing it in persistence.xml, but if I want to use a #NamedQuery, it doesn't work unless I list it in persistence.xml. Is there a way around this?
I am using Tomcat 8 with OpenJPA 2.4.2.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence
version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<!-- Used for persisting events, authentication pieces -->
<persistence-unit name="PushPersistence" transaction-type="RESOURCE_LOCAL">
<!-- Use Apache's OpenJPA -->
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<!-- Our backing store is our data source from context.xml -->
<non-jta-data-source>java:comp/env/jdbc/webservice</non-jta-data-source>
<!--
Without this, I can load and persist the entity but
CANNOT use Named Queries
-->
<class>push.authentication.AuthCredentials</class>
<!-- Don't require listing the managed classes here -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="openjpa.DynamicEnhancementAgent" value="true"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
<property name="openjpa.Log" value="SQL=TRACE"/>
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
</properties>
</persistence-unit>
</persistence>
Maven:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>MyProj</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<!-- Tell Maven what language version to use -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
</dependency>
<!-- Enables the annotations, etc needed -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<exclusions>
<exclusion>
<groupId>javax.exterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Our jersey libs -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
<!-- CDI to JAX-RS Binding -->
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers.glassfish/jersey-gf-cdi-ban-custom-hk2-binding -->
<dependency>
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
<artifactId>jersey-gf-cdi</artifactId>
<version>2.14</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.weld.servlet/weld-servlet-core -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>3.0.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.weld/weld-core-impl -->
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
<version>3.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>
<build>
<!-- We don't use the version number in the war file name -->
<finalName>MyProj</finalName>
<plugins>
<!-- Enhances the JPA classes -->
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<id>JPA Enhance</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<includes>**/push/*.class</includes>
<persistenceXmlFile>${project.basedir}/src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
<toolProperties>
<property>
<name>addDefaultConstructor</name>
<value>false</value>
</property>
<property>
<name>enforcePropertyRestrictions</name>
<value>true</value>
</property>
</toolProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Class declaration of named query:
package push;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Base64;
import java.util.Date;
#Entity
#NamedQueries(
{
#NamedQuery(
name = "Users.findByName",
query = "SELECT ac FROM Users ac WHERE ac.userName = :userName"
)
}
)
#Table(name = "PushClient")
public class Users
{
...
}
I read the EntityManager Interface and it says it throws IllegalArgumentException if a query has not been defined with the given name or if the query string is found to be invalid or if the query result is found to not be assignable to the specified type and if get IllegalArgumentException based on your snippet of code I think the third one is your case, try to use
EntityManager.createNamedQuery(java.lang.String name);
instead of
EntityManager.createNamedQuery(java.lang.String name,
java.lang.Class<T> resultClass);
And see if you get the same result or not
I'm working on a project made with :
Web Dynamic Project + JPA 2.1 / EclipseLink 2.5.2
Tomcat 8.0.28 / JRE 1.8.0_66
Eclipse Luna
JPA part of the project was running fine when executed in a simple JPA project as a Java Application.
I made no changes on that part of the code.
I wanted to print some request results in a JSP. I generated a servlet and tried to print the name of a user already created in the database. For hours I had errors about JDBC driver and persistence.xml not found.
In order to solve dependancies problems I added Maven.
Now, my user is printed in the JSP and that's fine, but my "Run.java" class I used previously doesn't work anymore.
I'm quiet lost with the error I get when running my app as a "Java Application" :
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.<clinit>(EntityManagerFactoryProvider.java:55)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:92)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at dao.LayerDAO.<init>(LayerDAO.java:16)
at exec.Run.main(Run.java:18)
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.platform.server.NoServerPlatformDetector.checkPlatform(NoServerPlatformDetector.java:28)
at org.eclipse.persistence.platform.server.ServerPlatformUtils.detectServerPlatform(ServerPlatformUtils.java:58)
at org.eclipse.persistence.internal.jpa.IsolatedHashMap.<clinit>(IsolatedHashMap.java:48)
... 7 more
Clearly the error occurs when I'm creating the EntityManagerFactory in the DAO class (the same one that is working with the JSP).
Here is my POM :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CitizenWeb</groupId>
<artifactId>com.citizenweb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- Generic properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Web -->
<jsp.version>2.2</jsp.version>
<jstl.version>1.2</jstl.version>
<servlet.version>2.5</servlet.version>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<!-- Other Web dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
<!-- EclipseLink -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.2</version>
</dependency>
<!-- MySQL DB -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
</dependencies>
</project>
If needed, here is my persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="CitizenWeb" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<mapping-file>META-INF/orm.xml</mapping-file>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/citizen"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="user"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
Entities mapping is managed with an orm.xml
Here's also the beginning of the DAO class :
package dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import entities.Address;
import entities.GroupAssoc;
import entities.RightsGranted;
import entities.User;
public class LayerDAO implements IFLayerDAOLocal {
EntityManager em = Persistence.createEntityManagerFactory("CitizenWeb").createEntityManager();
public void createUser(User user) {
System.out.println("DAO > addUser > "+em.hashCode());
em.getTransaction().begin();
em.persist(user);
em.getTransaction().commit();
}
Nothing has been changed here, neither in the persistence.xml
The "only" changes are in the build.path because of the change in the nature of project (JPA -> Web Dynamic+JPA). Maven has solved the problem with the webserver and the mysql connector, but now the app side is broken.
Do you see something I don't ?
Thanx.
In the buildpath of the project, I added an alternate "JRE System Library".
I previously had : JDK 1.8.0_66
I added : JRE 1.8.0_66
Now JSP works and also java Run class.
I'm creating simple java web app that writes one row of data to HBase table via JPA2 (using Datanucleus) everything working except it writing 2 duplicate rows instead of just writing 1 row
Results
ROW COLUMN+CELL
402881813acfed78013acfed78e00000 column=ACCOUNT_TABLE:FIRSTNAME, timestamp=1352108207916, value=testname
402881813acfed78013acfed78e00000 column=ACCOUNT_TABLE:ID, timestamp=1352108207916, value=402881813acfed78013acfed78e00000
402881813acfed78013acfed78e00000 column=ACCOUNT_TABLE:LASTNAME, timestamp=1352108207916, value=testname2
402881813acfed78013acfed78e00000 column=ACCOUNT_TABLE:LEVEL, timestamp=1352108207916, value=\x00\x00\x00\x03
402881813acfed78013acfedf7e20001 column=ACCOUNT_TABLE:FIRSTNAME, timestamp=1352108210172, value=testname
402881813acfed78013acfedf7e20001 column=ACCOUNT_TABLE:ID, timestamp=1352108210172, value=402881813acfed78013acfedf7e20001
402881813acfed78013acfedf7e20001 column=ACCOUNT_TABLE:LASTNAME, timestamp=1352108210172, value=testname2
402881813acfed78013acfedf7e20001 column=ACCOUNT_TABLE:LEVEL, timestamp=1352108210172, value=\x00\x00\x00\x03
2 row(s) in 0.1270 seconds
Datanucleus version in pom.xml
<org.datanucleus-version>3.1.1</org.datanucleus-version>
dependencies in pom.xml
<dependencies>
<!-- JPA 2.0 Spec -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<!-- JDO API -->
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0</version>
</dependency>
<!-- DataNucleus HBase -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-hbase</artifactId>
<version>${org.datanucleus-version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.94.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.3</version>
</dependency>
<!-- DataNucleus Core -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${org.datanucleus-version}</version>
<scope>runtime</scope>
</dependency>
<!-- DataNucleus Enhancer -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-enhancer</artifactId>
<version>${org.datanucleus-version}</version>
</dependency>
<!-- DataNucleus JPA api -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>${org.datanucleus-version}</version>
</dependency>
Plugin in pom.xml
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>${org.datanucleus-version}</version>
<configuration>
<api>JPA</api>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<persistenceUnitName>hbase-test</persistenceUnitName>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Account.java
package org.test.model;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "ACCOUNT_TABLE")
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name = "ACCOUNT_TABLE:ID")
#GeneratedValue(strategy = GenerationType.AUTO)
private String id;
#Column(name = "ACCOUNT_TABLE:FIRSTNAME")
private String firstName;
#Column(name = "ACCOUNT_TABLE:LASTNAME")
private String lastName;
#Column(name = "ACCOUNT_TABLE:LEVEL")
private int level = 0;
public Account() {
}
public Account(String firstName, String lastName, int level) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.level = level;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
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-unit name="hbase-test" transaction-type="RESOURCE_LOCAL">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<mapping-file>org/test/model/orm.xml</mapping-file>
<class>org.test.model.Account</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="datanucleus.storeManagerType" value="hbase" />
<property name="datanucleus.ConnectionURL" value="hbase:localhost:60010"/>
<property name="datanucleus.ConnectionUserName" value=""/>
<property name="datanucleus.ConnectionPassword" value=""/>
<property name="datanucleus.autoCreateSchema" value="true"/>
<property name="datanucleus.autoCreateTables" value="true" />
<property name="datanucleus.autoCreateColumns" value="true" />
<property name="datanucleus.validateTables" value="true"/>
<property name="datanucleus.validateConstraints" value="false"/>
<property name="datanucleus.Optimistic" value="false"/>
<property name="datanucleus.Multithreaded" value="true" />
</properties>
</persistence-unit>
</persistence>
orm.xml
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0">
<description>JPA Mapping file for Test</description>
<package>org.test.model</package>
<entity class="org.test.model.Account" name="Account">
<table name="ACCOUNT_TABLE" />
<attributes>
<id name="id">
<generated-value strategy="AUTO"/>
</id>
<basic name="firstName">
<column name="ACCOUNT_TABLE:FIRSTNAME"/>
</basic>
<basic name="lastName">
<column name="ACCOUNT_TABLE:LASTNAME"/>
</basic>
<basic name="level">
<column name="ACCOUNT_TABLE:LEVEL"/>
</basic>
</attributes>
</entity>
</entity-mappings>
TestAddAccountRow.java
package org.test.app;
import org.test.model.Account;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class TestAddAccountRow {
public void addAccount() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("hbase-test");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = null;
Account a2 = new Account("testname","testname2",3);
tx = em.getTransaction();
tx.begin();
em.persist(a2);
tx.commit();
}
}
UPDATE
#Datanucleus
I had code in spring mvc controller calling DAO (adding Account object), i don't know why but this was causing the duplicate rows, Datanucleus works perfectly.
While i couldn't find why it was creating duplicate rows, i swap out Datanucleus for Kundera it seems to solve the problem of duplicate rows
I think there a bug in Datanucleus
Kundera version number
<kundera-version>2.1</kundera-version>
pom.xml dependencies
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.impetus.core</groupId>
<artifactId>kundera-core</artifactId>
<version>${kundera-version}</version>
</dependency>
<dependency>
<groupId>com.impetus.client</groupId>
<artifactId>kundera-hbase</artifactId>
<version>${kundera-version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.impetus.kundera.rest</groupId>
<artifactId>kundera-rest</artifactId>
<version>${kundera-version}</version>
</dependency>
<!-- HBase and Hadoop -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.94.0</version>
</dependency>
persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2010 Bartosch Warzecha, Matthias Weßendorf
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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_2_0.xsd"
version="2.0">
<persistence-unit name="hbase">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>org.test.model.Account</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="60010" />
<property name="kundera.keyspace" value="test" />
<property name="kundera.dialect" value="hbase" />
<property name="kundera.client.lookup.class" value="com.impetus.client.hbase.HBaseClientFactory" />
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
<property name="kundera.ddl.auto.prepare" value="create" />
</properties>
</persistence-unit>
</persistence>
I've been trying to get a simple skeleton app to run (and commit to the DB) using JPA, MySQL, Hibernate & Maven, however I'm having problems.
Listed below are my 2 trivial classes, my pom.xml, and my META-INF/persistence.xml
I can build the project without any problem (mvn clean install), however running it (mvn exec:java -Dexec.mainClass=com.foo.HelloWorld -X) causes an exception, with the following StackTrace.
Any help would be greatly appreciated!
Stacktrace:
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:346)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:291)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/engine/SessionImplementor;
at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:142)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:646)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
at com.foo.HelloWorld.create(HelloWorld.java:32)
at com.foo.HelloWorld.main(HelloWorld.java:11)
... 6 more
I have the following two classes:
The Entity to store.
package com.foo;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class Message {
#Id
#GeneratedValue
private int id;
#Basic
private String message;
public Message() {}
public Message(String message) {
this.message = message;
}
public String toString() {
return "Greeting id=" + id + ", message=" + message;
}
}
The Application:
package com.foo;
public class HelloWorld {
private javax.persistence.EntityManagerFactory emf;
private javax.persistence.EntityManager em;
private String PERSISTENCE_UNIT_NAME = "hello-world";
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
hello.initEntityManager();
hello.create();
// hello.read();
hello.closeEntityManager();
}
private void initEntityManager() {
emf = javax.persistence.Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = emf.createEntityManager();
}
private void closeEntityManager() {
em.close();
emf.close();
}
private void create() {
em.getTransaction().begin();
Message hello = new Message("hello world");
Message bye = new Message("goodbye, world");
Message[] messages = new Message[] {hello, bye};
for (Message m : messages) {
em.persist(m);
}
em.getTransaction().commit();
}
// private void read() {
// Message m = (Message)em.createQuery("select m from Message m").getSingleResult();
// System.out.println("Query returned: " + m);
// }
}
The following is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.treocht.hibernate.tutorial</groupId>
<artifactId>hibernate-tutorial</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>First Hibernate Tutorial</name>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.2.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.2.1.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.2.1.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.beta9a</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<!--
we dont want the version to be part of the generated war file name
-->
<finalName>${artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And I have this META-INF/persistence.xml file:
<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 persistence_1_0.xsd"
version="1.0">
<persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.foo.Message</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/my_db" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.connection.username" value="username" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
You're indeed using incompatible versions of Hibernate artifacts as this can be verified using the official Hibernate Compatibility Matrix. Don't rely on some random tutorial found around the net for that.
But since you're using Maven, you actually don't need to declare all Hibernate artifacts, just leverage the transitive dependencies. So just declare a dependency in the hibernate-entitymanager (especially if you're not sure of what you're doing):
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version><!-- for JPA 1.0 -->
</dependency>
And remove these hibernate, hibernate-core, hibernate-annotations, persistence-api, slf4j dependencies.
And if you want to change the version of the sfl4j-api artifact that you get transitively, you should do that in the dependency management section:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</dependencyManagement>
Actually (and I'm sorry to say so) your whole pom is a big mess, try to spend some time cleaning it. Use mvn dependency:tree (or some visual fronted offered by your IDE) to do so.
And let me insist, don't rely on some random (and wrong) tutorial found around the net, leverage Maven transitive dependency mechanism.
PS: As of Hibernate 3.5, the various projects (Hibernate Annotation, Hibernate EntityManager) have been merged back to Hibernate Core and their versions are synchronized which simplifies a lot version management, even for Maven users.
There might be the conflicts in version.
compare it with this
This is now working, and my pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.hibernate.tutorial</groupId>
<artifactId>hibernate-tutorial</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Hibernate Tutorial</name>
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
</repositories>
<dependencies>
<!-- Hibernate framework -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version><!-- for JPA 1.0 -->
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>