While trying to run a JPA application, I get:
[EL Fine]: 2014-07-09 16:55:52.532--Thread(Thread[http-bio-8080-exec-6,5,main])--Detected database platform: org.eclipse.persistence.platform.database.HSQLPlatform
Which is NOT the correct platform. (should be an Oracle thin client). The
same project when checked out on a different machine works fine. Only
difference that we can detect is the jdk version (13 versus 60 on mine).
My Persistance.xml looks like:
<?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_2_0.xsd">
<persistence-unit name="JPA_DatabasePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>wellsDB</non-jta-data-source>
<class>my.domain.jpaDatabase.entities.Fred.Feature</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:user#//db.domain.my:1521/inst"/>
<property name="javax.persistence.jdbc.user" value="username"/>
<property name="javax.persistence.jdbc.password" value="password"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
What am I missing??
You could try to set the target database?
<property name="eclipselink.target-database" value="Oracle"/>
Well the answer was to replace the Tomee 1.5 install with a fresh install of Tomee 1.6. I cant see difference in the conf files but there you are. From my point of view, the important thing is that this fixed the issue. The created war deploys without a problem on the production Tomee as well.
Related
I was able to get JPA working with eclipse Luna and installing eclipseLink (and created a User Lib with the 3 jars).
However, I have now moved to Rational Application Developer (RAD) and attempting to use the JPA that is delivered with WAS Liberty. I initially used RAD JPA facet to configure JPA and then edited persistence.xml.
I am getting this error:
Caused by: javax.persistence.PersistenceException: No persistence providers available for "test2" after trying the following discovered implementations: NONE
I assume (always dangerous) the NONE is a configuration error and I cannot do anything until that is resolved...
I have copied the wlp\dev\api\spec\com.ibm.ws.javaee.persistence.2.0_1.0.1.jar into WEB-INF/lib and included that in my java build path.
As you can see below, I was guessing my provider was not correct, and tried several values...
<?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="test2" transaction-type="RESOURCE_LOCAL">
<!-- provider>org.eclipse.persistence.jpa.PersistenceProvider</provider-->
<!-- provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider-->
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>java:comp/env/New Generic JDBC</non-jta-data-source>
<class>com.ibm.analytics.jpa.Dimtask</class>
<properties>
<property name="openjpa.jdbc.Schema" value="RM"/>
<property name="javax.persistence.jdbc.url" value="jdbc:netezza://netezza-1.site.ibm.com:5480/DATABASENAME"/>
<property name="javax.persistence.jdbc.user" value="jspoon"/>
<property name="javax.persistence.jdbc.password" value="xxxxxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.netezza.Driver"/>
</properties>
</persistence-unit>
</persistence>
What else can I do to get past the NONE?
Here is the updated version of persistence.xml, I just commented out the provider.
<?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="test2" transaction-type="RESOURCE_LOCAL">
<!-- provider>org.eclipse.persistence.jpa.PersistenceProvider</provider-->
<!-- provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider-->
<!-- provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider-->
<non-jta-data-source>java:comp/env/New Generic JDBC</non-jta-data-source>
<class>com.ibm.analytics.jpa.Dimtask</class>
<properties>
<property name="openjpa.jdbc.Schema" value="RM"/>
<property name="javax.persistence.jdbc.url" value="jdbc:netezza://netezza-1.boulder.ibm.com:5480/BACC_TST_ISHANGO_DW"/>
<property name="javax.persistence.jdbc.user" value="jspoon"/>
<property name="javax.persistence.jdbc.password" value="C0ke4y0u"/>
<property name="javax.persistence.jdbc.driver" value="org.netezza.Driver"/>
</properties>
</persistence-unit>
</persistence>
I created my Entity class using JPA Tooling, and using a simple junit test to call a named query. The first step is to create the EMF and it is a static in my class (so none of the test is actually running, it is failing at instantiation creating the static variable):
static EntityManagerFactory emf = Persistence.createEntityManagerFactory( "test2" );
This is the exact same code as used before with eclipse and eclipseLink.
I have a newbie question, so I hope you can help.
Currently as ORM tool I am using OpenJPA 2.2.1 .
MY CUrrent persistence UNit:
<?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" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="FleaCircus" transaction-type="JTA">
<description>Flea Circus</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>FleaCircusOracleDS</jta-data-source>
<class>de.carmedialab.db.entities.ApplicationItem</class>
<class>de.carmedialab.db.entities.FleaResult</class>
<class>de.carmedialab.db.entities.FleaResultType</class>
<class>de.carmedialab.db.entities.ItemAttribute</class>
<class>de.carmedialab.db.entities.ItemGroup</class>
<class>de.carmedialab.db.entities.ItemType</class>
<class>de.carmedialab.db.entities.ItemTypeAttribute</class>
<class>de.carmedialab.db.entities.ItemTypeOperationAttribute</class>
<class>de.carmedialab.db.entities.Operation</class>
<class>de.carmedialab.db.entities.OperationAttribute</class>
<class>de.carmedialab.db.entities.OperationType</class>
<class>de.carmedialab.db.entities.Role</class>
<class>de.carmedialab.db.entities.UserAccount</class>
<class>de.carmedialab.db.entities.Measurement</class>
<class>de.carmedialab.db.entities.MeasurementType</class>
<class>de.carmedialab.db.entities.MeasurementAttribute</class>
<class>de.carmedialab.db.entities.MeasurementAttributeType</class>
<class>de.carmedialab.db.entities.Fleet</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="validate" />
<property
name="openjpa.Compatibility.CheckDatabaseForCascadePersistToDetachedEntity"
value="true" />
<!--<property name="openjpa.Log"
value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />-->
</properties>
</persistence-unit>
<persistence-unit name="FleaCircusLocal" transaction-type="RESOURCE_LOCAL">
<description>Flea Circus</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>FleaCircusOracleDS</non-jta-data-source>
<class>de.carmedialab.db.entities.ApplicationItem</class>
<class>de.carmedialab.db.entities.FleaResult</class>
<class>de.carmedialab.db.entities.FleaResultType</class>
<class>de.carmedialab.db.entities.ItemAttribute</class>
<class>de.carmedialab.db.entities.ItemGroup</class>
<class>de.carmedialab.db.entities.ItemType</class>
<class>de.carmedialab.db.entities.ItemTypeAttribute</class>
<class>de.carmedialab.db.entities.ItemTypeOperationAttribute</class>
<class>de.carmedialab.db.entities.Operation</class>
<class>de.carmedialab.db.entities.OperationAttribute</class>
<class>de.carmedialab.db.entities.OperationType</class>
<class>de.carmedialab.db.entities.Role</class>
<class>de.carmedialab.db.entities.UserAccount</class>
<class>de.carmedialab.db.entities.Measurement</class>
<class>de.carmedialab.db.entities.MeasurementType</class>
<class>de.carmedialab.db.entities.MeasurementAttribute</class>
<class>de.carmedialab.db.entities.MeasurementAttributeType</class>
<class>de.carmedialab.db.entities.Fleet</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="validate" />
<property
name="openjpa.Compatibility.CheckDatabaseForCascadePersistToDetachedEntity"
value="true" />
<!--<property name="openjpa.Log"
value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />-->
</properties>
</persistence-unit>
</persistence>
For the sake of simplicity, persistence-unit "FleaCircus" is what I use ( Container Managed Persistence ). FleaCircusLocal is another test pu I created , where I've created a sample stateless bean that basically starts a new transaction, persist an element and commit it.
However it doesn't sinchronize immediatly and customer complains about it.
Is there any way to make OpenJPA makes whats in context immediatly visible to the DB or is it impossible due to the nature as OpenJPA/JPA was thought ?
For me it is not a big deal since data is visible inside the container ( Apache Geronimo ) however for the customer it is important since he wants to connet using 3rd party tool ( eg. SQL Developer to and see if data was inserted or not .)
I'm trying to use jpa with tomcat, with Derby. But I get this message : Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database.
My persistence.xml is something like that :
<?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="contribs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:~/contribs;create=true"/>
<property name="javax.persistence.jdbc.password" value="sa"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
I use a ServletContextListener, annotated with #WebListener().
On contextInitialized I get a EntityManagerFactory and an EntityManager, and I close all on contextDestroyed.
I see with log tomcat call twice my ServletContextListener (I don't understand why), and the second time I get the error message.
Also I use Netbeans.
How can I resolve that ? Thanks.
Are you hot-redeploying your application into Tomcat? Tomcat appears to frequently keep multiple copies of the web-app running, in separate application class loaders, and only one copy of your web-app is able to open Derby at a time.
One possibility is to switch from the Embedded version of Derby to the Client-Server version.
Another possibility is to restart Tomcat when the problem occurs.
My application uses JPA and JavaDB in embedded mode. In the persistence.xml file I use this property:
<property name="javax.persistence.jdbc.url" value="jdbc:derby:meuspiladb;create=true" />
so an empty database will be created if it does not exist yet.
Currently I have a create_tables.sql file where I put the SQL code to create the tables, and then I run it manually after the database is created. I would like to make this be automatic but I don't know how.
If the database is new I have to create the tables. What is the best way to create them from Java code?
My persistence.xml file:
<?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="MeusPila3_PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>br.meuspila.corretora.Corretora</class>
<class>br.meuspila.ativo.Ativo</class>
<class>br.meuspila.bolsa.Bolsa</class>
<class>br.meuspila.movimento.Movimento</class>
<class>br.meuspila.provento.Provento</class>
<class>br.meuspila.operacao.Operacao</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:meuspiladb;create=true" />
<property name="javax.persistence.jdbc.user" value="APP"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
</properties>
</persistence-unit>
</persistence>
You can use Hibernate with JPA, then use configuration option hibernate.hbm2ddl.auto=create.
I have embedded derby database and i work with jpa. This is my persistence.xml:
<?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="pers">
<class>entities.Leverancier</class>
<class>entities.Prijsproduct</class>
<class>entities.Product</class>
</persistence-unit>
</persistence>
What should i change or add to get this working. When I run my code now I get the following:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at test.Test.main(Test.java:19)
Your persistence.xml is not correct. Look at a sample below:
<persistence-unit name="MyAppPU" transaction-type="RESOURCE_LOCAL">
<!-- This is where you mention your JPA runtime provider e.g. it's EclipseLink here -->
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>mypkg.MyEntity</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/my_schema"/>
<property name="javax.persistence.jdbc.password" value="pass"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user" value="user"/>
</properties>
</persistence-unit>
You also have to make sure that you put your JPA provider jar files (along with the derby-client jar) in the classpath.