I'm running into an issue where I can't get Quarkus to work with persistence.xml.
My entities are not discovered so I always get "Not an entity" errors when querying.
(Caused by: java.lang.IllegalArgumentException: Not an entity: ...)
Using Quarkus 1.13.5.Final
This might be related to Quarkus Panache Not Working with persistence.xml after 1.8
I'm migrating an existing app, I only have a single project that contains all the entities. I only use a single persistence unit.
My persistence.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="registry-pu" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.jdbc.time_zone" value="UTC"/>
</properties>
</persistence-unit>
</persistence>
I'm only specifying these additional env variables:
QUARKUS_DATASOURCE_USERNAME=
QUARKUS_DATASOURCE_PASSWORD=
QUARKUS_DATASOURCE_JDBC_URL=
I'm also only relying on this persistence.xml because the app being migrated needs the enable_lazy_load_no_trans prop to work
Any help would be appreciated
Found I had to add <class>EntityClass</class> entries to the <persistence-unit> tag for each of my entities to have them included. Otherwise you may be able to try <exclude-unlisted-classes>false</exclude-unlisted-classes>
Related
My persistence file content: "jdbc:derby:deliceplaceDB;create=true". But I when execute "mvn clean javafx:run" the database "deliceplaceDB" is not created. Please need help!!!
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="deliceplacePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:deliceplaceDB;create=true" />
<property name="javax.persistence.sql-load-script-source" value="sql/create.sql"/>
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
</properties>
</persistence-unit>
</persistence>
And I would like to load my sql file "create.sql" at runtime but is not working.
thanks
You've specified a load script source - which is used for post creation scripts - and specified DDL generation would go to the database, but this only occurs once you turn it on.
specify properties:
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="javax.persistence.schema-generation.create-source" value="script"/>
<property name="javax.persistence.schema-generation.create-script-source" value="sql/create.sql"/>
the first tell JPA to create the database when deploying, the second tells it to look for a script, the third where the script is.
See here for a good description of other options, and check and post the logs if there are any problem.
I am stuck setting up a simple test program with
- eclipse
- gradle (Eclipse Buildship plugin)
- openjpa
When I try to run my application I get this error, when I call the entityManager.persist(...) method:
Exception in thread "main" org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "test.jpa.Person#27c6e487" to PersistenceCapable failed. Ensure that it has been enhanced.
FailedObject: test.jpa.Person#27c6e487
The program is simple, it just has one entity (Person.java).
My persistence.xml 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="ptest"
transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/ptest" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="..." />
<property name="openjpa.ConnectionPassword" value="..." />
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
<property name="openjpa.Log" value="SQL=ERROR" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.ConnectionFactoryProperties"
value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000" />
</properties>
</persistence-unit>
</persistence>
I have used RuntimeUnenhancedClasses=unsupported and DynamicEnhancementAgent=false, for it was recommended by apache. But I have tried with "supported" and "true" and I still get the same error (for openjpa version 2.1.0 - for higher versions I get a LinageError with "supported/true").
I have tried different versions of jpa, currently using 2.4.2.
I have goodled for gradle scripts to enhance my class, I tried
'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
'neva.openjpa'
and some more, but I just cannot enhance the class.
Of course I have goodled for quite some time. I am thankful for any idea I can follow...
Thanks in advance!
Just in case someone else has the same struggle. I have found a solution to this problem:
TomEE ships with JPA and everything that is needed. The eclipse "gradle buildship" plugin can be used to compile code. So the combination of the following components works perfectly fine for me:
apache-tomee-plus-7.0.2
tomcat v8.5 server (pointing to the apache-tommee installation)
Dynamic Web Project (using Dynamic Web Module 3.1)
Java Runtime Environment v1.8
The gradle script reduces simply to this:
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
providedCompile "javax:javaee-api:7.0"
}
I suppose it also works with TomEE 1.7.x and javaee-api:6.0, but I have not tried it.
I have a Hibernate / Spring 4 application, where the default schema of the entity classes is already configured, e.g. they end up mapped as testschema.table or prodschema.table.
However there is another entity class which needs its own configurable schema, e.g. only this entity must be mapped to testschema2.anothertable or prodschema2.anothertable.
Nice would be something like this:
#Entity
#Table(name="anothertable", schema = "${db.AntherEntitySchema}")
public class AnotherEntity {
// ..
}
where the schema gets injected from the properties file, but such a feature seems only to work with the #Value annotation.
Any idea how to proceed?
We solved it by this applicationContextPersistence.ctx.xml
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation"
value="classpath:META-INF/persistence-${env}.xml" />
<!-- .. -->
</bean>
where Spring can substitute the ${} expression from a property file.
We then have a persistence-dev.xml etc which features a specific orm-dev.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="fooUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<mapping-file>META-INF/orm-dev.xml</mapping-file>
</persistence-unit>
<!-- .. -->
</persistence>
The orm-dev.xml is now responsible for the entity mapping:
<?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> XML Mapping file</description>
<package>foo.server.model</package>
<entity class="AnotherEntity">
<table schema="testschema2" name="anothertable" />
<attributes>
<!-- .. -->
</attributes>
</entity>
</entity-mappings>
Finally we removed the mapping annotations from the AnotherEntity POJO, as this one is now mapped via the orm-dev.xml file. The other enitity classes kept their annotations.
Note: We use the Spring Tool Suite flavour of Eclipse. This IDE expects a persistence.xml, so to get rid of an error message we kept a minimal persistence.xml to not have to remember the IDE option which deactivates the validator.
I'm trying to get a simple web app called Debugger running under Tomcat 7 using Spring 3.2.1 and OpenJPA. I use Eclipse as the IDE and run Tomcat external to the IDE. I'm getting a error when the WAR is being deployed. This is the error message:
org.apache.openjpa.persistence.ArgumentException: No persistent class is specified in eager initialization mode.
Here is the persistence.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"
version="2.0">
<persistence-unit name="applicationDB" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>
<property name="openjpa.InitializeEagerly" value="true"/>
<property name="openjpa.DynamicEnhancementAgent" value="false"/>
</properties>
</persistence-unit>
</persistence>
Is the error caused by not having any classes specified in this file? I'm just trying to get a base application configuration setup so I'm not yet ready to place any classes in the persistence file. Maybe you have to have at least one?
Either list your persistent classes, or remove the openjpa.InitializeEagerly property.
So i Have this problem in implementing JPA and Hibernate in Spring WS. I have configured everything correctly and according to tutorial it should work - but it is not.
Problem lies in persistance.xml, here it is how it looks:
<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/persistance_1_0.xsd"
version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
</properties>
</persistence-unit>
</persistence>
and the exception i am getting:
Caused by: java.io.FileNotFoundException: class path resource [persistence_1_0.xsd] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:177)
at org.springframework.orm.jpa.PersistenceUnitReader.validateResource(PersistenceUnitReader.java:281)
at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:108)
... 57 more
I am struggling with this since a while... Do anyone have an idea what am i missing?
You need to include appropriate jar file containing the persistence_1_0.xsd.
This is explained here.
what is the use of xsi:schemaLocation?
There was a type in the url to the .xsd file. Try using: http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd . A good way to debug these types of issues is to try to hit the url in your browser, a successful request denotes a valid link.
<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="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
</properties>
</persistence-unit>
</persistence>
You make sure your project name does not contain any spaces, nor should the path to the project. This creates an error in Hibernate entity manager.