I'm trying to convert my hibernate-based GWT implementation into a JPA2 version. I've added the persistence.xml, the specific libraries and added some code just to open (by getting an entityManager). I just do a local employment, I do not use google's app engine (and I'm not intended to use it).
I get the following message:
Cannot connect to MySQL database
server (Provider error. Provider:
org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider),
exiting
My persistence.xml looks like:
<?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_1_0.xsd"
version="1.0">
<persistence-unit name="mydatabase_dev">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>mypackage.Product</class>
<class>mypackage.Expert</class>
<class>mypackage.Person</class>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://myhost.mydomain/MYDATABASE"/>
<property name="hibernate.connection.username" value="myusername"/>
<property name="hibernate.connection.password" value="topsecret"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<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"/>
<!-- Disable the second-level cache -->
<property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
</properties>
</persistence-unit>
</persistence>
There is no other error message, warning, stacktrace, etc.
What is wrong or in what way can I examine what the real problem is?
GAE/J doesn't do MySQL, nor JPA2 so why are you including it/specifying it in your persistence.xml? Perhaps if you post your persistence.xml then people can make an informed opinion ...
Related
I'm having troubles with "working with multiple databases" in Spring MVC - hibernate JPA
I have two databases called user_db and portal_db. I need to work with them in different jpa units.
here is my persistance.xml
<?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_1_0.xsd" version="1.0">
<persistence-unit name="user_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Package.Entity1</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/user_db" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop" />-->
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="portal_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Package.Entity2</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/portal_db" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop"/>-->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Problem is When I use create-drop and run my project, it creates both of my entites in both databases. Like table that should be only created by Package.Entity1 in user_unit, is also created in portal_unit.
And when I select,insert,update my entites, I set persistance unit in each of my individual DAO's.
for example, in Entity Dao's implementation I have:
EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit);
where persistenceUnit could be user_unit or portal_unit depending on implementation.
What changes should I make so it wont create same table in both databases?
Add <exclude-unlisted-classes>true</exclude-unlisted-classes> in both of yours persistence units OR use JPA 2.x
Add <exclude-unlisted-classes>true</exclude-unlisted-classes> in both your persistence units.
Please follow post below for detailed explanation:
Multiple persistance unit in persistence.xml creating tables in one another
I have simple problem. When I edit something directly in database for example by UPDATE statement I can't see any changes in my application. I read somewhere that this is reason of Hibernate cache or am wrong ?
My hibernate configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="transactionPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/TestTable?UseUnicode=true&characterEncoding=utf8" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="uberSecretUsername" />
<property name="hibernate.connection.password" value="uberSecretPassword" />
<property name="show_sql" value="true" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8" />
</properties>
</persistence-unit>
</persistence>
Its pretty basic nothing here that can surprise you. How can I disable this cache or how can I get this working. I just want simple see changes in app when I make changes directly on database
I've been searching around and haven't been able to find a working fix. My persistence.xml file is located in /src/META-INF/persistence.xml, which from looking around, this is the correct location for it.
I'm using glassfish as the server, and I keep getting the following:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers
Here is my persistence file:
<?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="pers" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>cs.ee.assignment2.Client</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/assignment2" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
Any ideas on what the problem could be would be greatly appreciated.
Hmm.. make sure you are using PeristenceUnit not context in your entity class: see http://openejb.apache.org/jpa-concepts.html
Switch to "transaction" just to see if it fails too.
Also sometimes the old classes are not unloaded from the server properly if you are doing redeployment, you may have to shut it down and restart after redeploy.
I am using this method in the following way
EntityManagerFactory emftemp = Persistence.createEntityManagerFactory("XYZ");
and my persistence.xml has the following entry for this unit
<persistence-unit name="XYZ" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.query.substitutions" value="true=1, false=0"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:#aesop-db.corp.nlg1.com:1521:TLCSDEV4"/>
<property name="hibernate.connection.username" value="abcd"/>
<property name="hibernate.connection.password" value="abcd"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/>
<property name="hibernate.connection.timeout" value="120"/>
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.min_size" value="2"/>
<property name="hibernate.c3p0.max_size" value="2"/>
<property name="hibernate.c3p0.idle_test_period" value="60"/>
</properties>
</persistence-unit>
This is a Java application and I am using the hibernate3.jar and I am using ejb3-persistence.jar and JDK1.5.
The problem is that everytime I run the application, it hangs on this call . Its not throwing any exception or error . It just hangs at that point.
Can anyone help in identifying why it does not move forward ?
Two thoughts:
When something hangs it's often IO/networking issues to blame. So, try to make sure that the DB is really alive, and that you can connect to it from your computer.
This could be a duplicate of Persistence.createEntityManagerFactory takes ages
I had this same issue against an Oracle 11g database with only three entities defined but a very large DB. After commenting out the following line from persistence.xml, the issue was resolved.
<property name="hibernate.hbm2ddl.auto" value="update"/>
I'm having some problem with EclipseLink. I'm using GlassFish v3.1 and I'm trying to use EclipseLink for my persistence layer. I followed all tutorials available on the Eclipse wiki without luck. My persistence.xml file cannot be parsed and I receive this error while trying to create the EntityManagerFactory:
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundle://307.1:1/
Here is my persistence.xml located in /WEB-INF/classes/META-INF/:
<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="generic">
<class>com.generic.domain.Service</class>
<properties>
<!-- Embedded MySQL Login -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"/>
<!-- TODO: replace with connection pool -->
<property name="javax.persistence.jdbc.userid" value="root"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<!-- Logging Settings -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="true" />
<property name="eclipselink.logging.timestamp" value="false"/>
</properties>
</persistence-unit>
</persistence>
I added this line to my MANIFEST.MF:
JPA-PersistenceUnits: generic
I can now confirm that it's a bug in EclipseLink. The work around to your problem is to either get hold of EntityManagerFactory using JNDI lookup or #PersistenceUnit instead of doing Persistence.createEntityManagerFactory().
1) It looks like you are trying to use OSGi/JPA from your WAB. Correct?
2) Can you tell if you have installed any new eclipselink bundles in your system? If so, what are they?
3) Can you provide stack trace?