Hibernate version:
hibernate-3.2
hibernate-annotations-3.3.1.GA
hibernate-entitymanager-3.3.2.GA
Mapping documents:
Full stack trace of any exception that occurs:
Initial EntityManagerFactory creation failed.javax.persistence.PersistenceException: No Persistence provider for EntityManager named manager1
Name and version of the database you are using:
PostGreSQL Database Server 8.3
I want to have a simple Eclipse RCP Application to access the Database, i am surely missing a detail, cause im still very new to using Hibernate.
I read some Forums and most suggestions say some Jars are missing. I put all Jars i could find in hibernate core, annotations and entity manager into one Plug-In(using "create Plug-In from JAR Files") and added the Plug-In to the Dependencies of the RCP.
List of JARs in the Plug-In:
xml-apis.jar
ant-1.6.5.jar
ant-antlr-1.6.5.jar
ant-junit-1.6.5.jar
ant-launcher-1.6.5.jar
antlr-2.7.6.jar
ant-swing-1.6.5.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
checkstyle-all.jar
cleanimports.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
concurrent-1.3.2.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
ehcache-1.2.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hsqldb-1.8.0.1.jar
ivy-1.4.1.jar
jaas.jar
jacc-1_0-fr.jar
javassist-3.1.jar
javassist.jar
jaxen-1.1-beta-7.jar
jboss-archive-browsing-5.0.0alpha-200607201-119.jar
jboss-cache.jar
jboss-common.jar
jboss-jmx.jar
jboss-system.jar
jgroups-2.2.8.jar
jta.jar
junit-3.8.1.jar
oscache-2.1.jar
persistence.jar
postgresql-8.3-603.jdbc2.jar
postgresql-8.3-603.jdbc2ee.jar
postgresql-8.3-603.jdbc3.jar
postgresql-8.3-603.jdbc4.jar
proxool-0.8.3.jar
swarmcache-1.0rc2.jar
syndiag2.jar
versioncheck.jar
xerces-2.6.2.jar
I put persistence.xml into META-INF of the RCP.
Looks like this
Code:
<?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="manager1" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entities.Address</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgresSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/TestDB"/>
<property name="hibernate.connection.username" value="<User>"/>
<property name="hibernate.connection.password" value="<PW>" />
<property name="hibernate.max_fetch_depth" value="7" />
<!-- debug properties -->
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Exception occurs in line ".createEntityManagerFactory(...)":
Code:
private static final EntityManagerFactory entityManagerFactory;
static {
try {
// Create the EntityManagerFactory
entityManagerFactory = Persistence.createEntityManagerFactory("manager1", new Properties());
} catch (Throwable e) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial EntityManagerFactory creation failed." + e);
throw new ExceptionInInitializerError(e);
}
}
I want to map a single Class called "Adress":
Code:
@Entity
public class Address implements Comparable<Address>, Cloneable, Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String city;
private String country;
private String street;
private String zip;
/**
* @return the id
*/
@Id @GeneratedValue
public Long getId() {
return id;
}
The calling class looks like this:
Code:
/**
* Application boot trap
* @param args
*/
public static void main(String[] args) {
// setup log4j logging facility
try {
SimpleLayout layout = new SimpleLayout();
ConsoleAppender consoleAppender = new ConsoleAppender( layout );
logger.addAppender( consoleAppender );
FileAppender fileAppender = new FileAppender( layout, "logfile.log", false );
logger.addAppender( fileAppender );
logger.setLevel( Level.DEBUG );
} catch( Exception ex ) {
System.out.println( ex );
}
// run DB Test DBTest
new DBTest().run();
public void run() {
// store Address object
Address address = new Address();
address.setCity("Stuttgard");
address.setCountry("Germany");
address.setStreet("Waldweg 45");
address.setZip("58421");
saveAddress(address);
/**
* Store an address object.
* @param address
*/
private void saveAddress(final Address address) {
EntityManager em = HibernateUtil.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.merge(address);
tx.commit();
em.close();
}
I just have the question wich point i'm missing or if there are any hints or known problems...
excuse me for the long post, i just wanna give all necessary information.
with beste regards
Nebelritter