I am trying to use the create-or-extend-tables of Eclipselink to create newly added columns. But the columns are not created in Database (MySQL). We are using EclipseLink 2.5.2 and Glassfish 4.1 (build 13).
Please any expert here help me on this.
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="createSunriseDB.sql"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropSunriseDB.sql"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.logging.level" value="SEVERE"/>
</properties>
Related
I am trying to setup Hibernate OGM to work with Play Framework 2.5.x(17) in my case but I keep getting "Cannot connect to database [default]" error. Apparantly Play takes MySQL driver as default and I am not able to find a driver configuration specifically for Neo4J.
Here is my persistance.xml file content:-
<?xml version="1.0"?>
<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="defaultPersistenceUnit" transaction-type="JTA">
<!-- Use Hib77ernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.transaction.jta.platform"
value="JBossTS" />
<property name="hibernate.ogm.datastore.provider" value="neo4j_http"/>
<property name="hibernate.ogm.datastore.host" value="localhost:7474"/>
<property name="hibernate.ogm.datastore.username" value="neo4j"/>
<property name="hibernate.ogm.datastore.password" value="neo4j"/>
</properties>
</persistence-unit>
</persistence>
And application.conf content:
db.default.jndiName=DefaultDS
jpa{
default=defaultPersistenceUnit
}
Any help is appreciated. Thanks in advance.
I was facing the same problem then I found one solution that we can use neo4j jdbc driver.
application.conf :-
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
db.default.driver=org.neo4j.jdbc.Driver
db.default.url="jdbc:neo4j:http://localhost"
db.default.user= neo4j
db.default.password="password"
persistence.xml
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>domain class name</class>
<properties>
<property name="hibernate.transaction.jta.platform"
value="JBossTS" />
<property name="hibernate.ogm.datastore.provider" value="neo4j_http"/>
<property name="hibernate.ogm.datastore.host" value="localhost:7474"/>
<property name="hibernate.ogm.datastore.username" value="neo4j"/>
<property name="hibernate.ogm.datastore.password" value="password"/>
</properties>
</persistence-unit>
There is some one that was able to configure the HQL tool of the eclipse hibernate tool? I have try to configure it using the JPA. My configuration generate all the Entity (that are observable in the configuration) and the connection to the database but the session factory return the following
Could not determine type for: org.hibernate.spatial.GeometryType, at table:....
There is a way to solve this problem, maybe adding some library or configuration?
I am using Postgis DB and the proprietis of the configuration are:
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="off" />
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect" />
</properties>
I am trying to set up JPA in my TomEE Plus. I have got my persistence.xml as below
<persistence-unit name="test" transaction-type="JTA">
<jta-data-source>jdbc/testDB</jta-data-source>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.TestEntity</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
When i deploy my App, i can't see any errors in the console. I can also see the logs which binds the PU to the JNDI.
But no tables are created in the DB.
Can some please help me in this?
If you are using the default JPA implementation shipped with TomEE (OpenJPA) rather than Hibernate, you should:
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
If <provider> is not specified in the persistence.xml ,then the container will use its default persistence provider .For TomEE ,its default persistence provider is OpenJPA.
The <properties> should match the persistence provider you are using .
So , if you are using OpenJPA , your persistence.xml should look like this: (OpenJPA 's <properties> can be found at here)
<persistence-unit name="test" transaction-type="JTA">
<jta-data-source>jdbc/testDB</jta-data-source>
<class>com.TestEntity</class>
<properties>
<property name="openjpa.jdbc.DBDictionary" value="mysql"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
</properties>
</persistence-unit>
If you want to use hibernate as the persistence provider , your persistence.xml should look like this:
<persistence-unit name="test" transaction-type="JTA">
<jta-data-source>jdbc/testDB</jta-data-source>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.TestEntity</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
I am using OpenJPA 1.2.3 on WebSphere with DB2.
Is there a way to build and bundle my application in a way that allows for the same application (EAR) to have a changing Schema name based on environment (DEV, ACPT, PROD, etc).
My PU is setup up to be container managed as follows:
<persistence>
<persistence-unit name="My_PU" transaction-type="JTA">
<jta-data-source>jdbc/DataSource</jta-data-source>
...
<properties>
<property name="openjpa.jdbc.Schema" value="MYSCHEMA"/>
<property name="openjpa.TransactionMode" value="managed"/>
<property name="openjpa.ConnectionFactoryMode" value="managed"/>
</properties>
</persistence-unit>
</persistence>
I have looked into putting this in the ORM.xml, but this is still a static value for the schema, and does not externalize the setting; also, it doesn't seem to work (I have seen the many threads discussing this). I also, have looked into putting this configuration into the WebSphere data source; this does not seem to work either.
--Keith
I'm not familiar with OpenJPA, but I'm guessing that the openjpa.jdbc.Schema property is optional. The datasource (i.e. the one at jdbc/DataSource) will dictate the default schema in use.
Have you tried leaving the property out?
You can use maven.
1-Define profiles for each build scenario in the project pom file or maven settings.
<profiles>
<profile>
<id>DEV Profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<propertis>
<db-schema>DEVSCHEMA</db-schema>
</propertis>
</profile>
<profile>
<id>PROD Profile</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<propertis>
<db-schema>PRODSCHEMA</db-schema>
</propertis>
</profile>
</profiles>
2- change your persistence.xml as follows:
<persistence>
<persistence-unit name="persistent-unit" transaction-type="JTA">
<jta-data-source>jdbc/DataSource</jta-data-source>
...
<properties>
<property name="openjpa.jdbc.Schema" value="${db-schema}"/>
<property name="openjpa.TransactionMode" value="managed"/>
<property name="openjpa.ConnectionFactoryMode" value="managed"/>
</properties>
</persistence-unit>
</persistence>
3- Put following lines in the project pom file.
<build>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<filtering>true</filtering>
<targetPath>/META-INF</targetPath>
</resource>
</resources>
</build>
I just create separate <persistence-unit> elements and then dynamically select which one to bind to.
For example:
<persistence>
<persistence-unit name="DEV_PU" transaction-type="JTA">
<jta-data-source>jdbc/DataSource</jta-data-source>
...
<properties>
<property name="openjpa.jdbc.Schema" value="DEVSCHEMA"/>
<property name="openjpa.TransactionMode" value="managed"/>
<property name="openjpa.ConnectionFactoryMode" value="managed"/>
</properties>
</persistence-unit>
<persistence-unit name="PROD_PU" transaction-type="JTA">
<jta-data-source>jdbc/DataSource</jta-data-source>
...
<properties>
<property name="openjpa.jdbc.Schema" value="PRODSCHEMA"/>
<property name="openjpa.TransactionMode" value="managed"/>
<property name="openjpa.ConnectionFactoryMode" value="managed"/>
</properties>
</persistence-unit>
</persistence>
You can set schema name dynamically in the code like so:
#Entity
#Table(name = "ITEM", schema=Item.SCHEMA)
public class Item implements Serializable {
public static final String SCHEMA = System.getProperty("env.schema");
#Id
#Column (name = "ITEM_ID")
private String id;
#Column (name = "ITEM_NAME")
private String name;
}
My IDE is eclipse -Helios and I am using mojarra jsf, mysql, eclipselink for jpa.
In my project, if I create the tables manually in mysql, I can see those tables in the "JPA Details" view. And if I don't create any table, the eclipse IDE shows an error, "Table "trainingsession" cannot be resolved".
I am not sure what's wrong. When would JPA create these tables ? and how ?
my persistence.xml is as follows,
<?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="wompower2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>trainer</jta-data-source>
<class>com.jsfcompref.trainer.entity.User</class>
<class>com.jsfcompref.trainer.entity.TrainingSession</class>
<class>com.jsfcompref.trainer.entity.Event</class>
<class>com.jsfcompref.trainer.entity.AbstractEntity</class>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
<property name="eclipselink.application-location" value="C:\wompower2\DDL"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="javax.persistence.jdbc.user" value="user"></property>
<property name="javax.persistence.jdbc.password" value="pwd"></property>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
</properties>
</persistence-unit>
</persistence>
Thank you,
Arindam.
First let me clarify that JPA is a standard spec for ORM and EclipseLink is one of the implementor of the spec (Hibernate is another example). The spec doesn't mandate the creation of the schema or tables though EclipseLink provides a mechanism to create the tables for you through configuration. Below are the two config properties controlling that
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
Go through this tutorial for more information (specifically 3.2 section)
GlassFish reads the property eclipselink.ddl-generation to decide whether it will use its own table generation functionality -- java2db. This only works during deployment and if the target is the DAS.
It doesn't matter the value of eclipselink.ddl-generation.output-mode you give, GlassFish will set it to "sql-script" if java2db is to be used (so that it can then run the scripts) or "none" if it is disabled. See glassfish3/persistence/jpa-connector/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java.
I saw "Table 'nnn' cannot be resolved" being reported after a couple of tests I made with JPA, MySQL, Eclipse.
My issue was caused by myself. I switched the data connection during my tests. But the tool - I assume I was the JPA plugin - was continuing to validate the table names against the first data connection i defined.
So, my solution was:
Open the project specific JPA properties (right click project -> JPA) and ensure that the connection settings refer to the correct database. Rebuild... that's it.
This is a bit late, but just in case anybody comes across this. You just need to run a query like an INSERT or a SELECT against the database and the tables will be created. It has worked for me before. I hope this help anybody with the same issue.
Just a persistence.xml example using eclipselink and mysql for others looking for a working solution:
<?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="java2curs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>db.YourClasses</class>
<properties>
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/dbname"/>
<property name="javax.persistence.jdbc.user" value="dbuser"/>
<property name="javax.persistence.jdbc.password" value="dbpassword"/>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>