i'm new in the world of java-ee. I try to implement an java-ee App. I'm having some trouble to configure the persistence.xml. I want the default java h2:mem to be my persistence unit. Hier is my 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"
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="customerDatabase">
<description>My Customer-DB</description>
</persistence-unit>
<datasource jndi-name="java:jboss/datasources/ExampleDS"
pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</persistence>
It's something wrong with it because i'm getting the error:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'datasource'. One of '{"http://java.sun.com/xml/ns/persistence":persistence-unit}'
is expected.
what does the persistence.xml miss?
I changed my provider and i'm now using hibernate... Now i'm getting errors from an other order. Can anybody helps?
11:21:46,092 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 59) MSC000001: Failed to start service jboss.persistenceunit."javaee7-master.war#customerDatabase": org.jboss.msc.service.StartException in service jboss.persistenceunit."javaee7-master.war#customerDatabase": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
... 7 more
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: de.ostfalia.entity.Customer
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
... 12 more
11:21:46,098 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "javaee7-master.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"javaee7-master.war#customerDatabase\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"javaee7-master.war#customerDatabase\": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: de.ostfalia.entity.Customer"}}
11:21:46,197 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "postgresql-9.4-1203.jdbc42.jar" (runtime-name : "postgresql-9.4-1203.jdbc42.jar")
11:21:46,198 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "javaee7-master.war" (runtime-name : "javaee7-master.war")
11:21:46,200 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.persistenceunit."javaee7-master.war#customerDatabase": org.jboss.msc.service.StartException in service jboss.persistenceunit."javaee7-master.war#customerDatabase": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
According to the official schema, the <persistence> element can only contain persistence-unit elements. I would suggest you start with upgrading from JPA 1.0 to 2.0 (requires Java 6) or 2.1 (requires Java 7). An example persistence.xml 2.1 would be as follows:
<?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="customerDatabase" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value="sa"/>
</properties>
</persistence-unit>
</persistence>
This configuration presumes your application gets the java:jboss/datasources/ExampleDS data source from some other configuration, like for example in Apache Tomcat, it would be in the context.xml and the properties listed in this example would not be necessary.
The provider is different if you're not using the EclipseLink library.
Also non-jta-data-source might have to be jta-data-source in your case.
update:
The error you are getting now comes from No identifier specified for entity: de.ostfalia.entity.Customer. You need to make sure all your entity classes have properly specified Id columns. If you are using JPA annotations, that would be the #Id annotation. You may also need a #GeneratedValue on it, if the database automatically assigns the ID on insert for that table (the most common case). There is also the option of specifying them through a mapping.xml file. These tutorials will get you started with good examples http://www.tutorialspoint.com/jpa/jpa_orm_components.htm http://www.javaworld.com/article/2077817/java-se/understanding-jpa-part-1-the-object-oriented-paradigm-of-data-persistence.html
One thing I learned the hard way is that every time you do EntityManager em = entityManagerFactory.createEntityManager(); you must em.close() it in the end, no matter if you've committed or rolled-back the transaction, which means you must also catch any Throwables that may occur. In our webapp, we do this by using a javax.servlet.Filter (only applies to webapps) for all urls. If you leave it open for too long with no activity, the database will eventually drop the connection (which might not happen in H2 specifically) and the thread becomes unusable until you restart the server.
Related
I have to configure my PostgreSQL datasource for WildFly in order to use it in my Jakarta EE 10 with hibernate 6.0.2
Below shown are my configuration
Postgresql module in widfly
<?xml version="1.0" ?>
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
Datasource
<datasource jndi-name="java:jboss/datasources/nextu" pool-name="nextu">
<connection-url>jdbc:postgresql://localhost:5432/nextu</connection-url>
<driver>postgres</driver>
<security>
<user-name>nextu</user-name>
<password>nextu</password>
</security>
</datasource>
Driver used
org.postgresql.Driver
Persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence
xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_1.xsd"
version="3.1">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/nextu</jta-data-source>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<!-- AUTO-GENERATES DATABASE FROM ANNOTATIONS METADATA -->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
</properties>
</persistence-unit>
</persistence>
Error I am getting while running:
00:50:49,304 ERROR [org.jboss.msc.service.fail] (ServerService
Thread Pool -- 80) MSC000001: Failed to start service
jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
org.jboss.msc.service.StartException in service
jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
java.lang.ExceptionInInitializerError at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:199)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:129)
at
java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at
org.wildfly.security.elytron-base#2.0.0.Beta3//org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:664)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:214)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833) at
org.jboss.threads#2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.ExceptionInInitializerError at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLDialect.contributeTypes(PostgreSQLDialect.java:1107)
at
org.hibernate#6.0.2.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:374)
at
org.hibernate#6.0.2.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:144)
at
org.hibernate#6.0.2.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
at
org.hibernate#6.0.2.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
at
org.hibernate.jipijapa-hibernate6#27.0.0.Alpha5//org.jboss.as.jpa.hibernate.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:45)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:171)
... 10 more Caused by: java.lang.RuntimeException: Could not
initialize PostgreSQLPGObjectJdbcType at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLIntervalSecondJdbcType.<clinit>(PostgreSQLIntervalSecondJdbcType.java:78)
... 17 more Caused by: java.lang.NoSuchMethodException:
org.postgresql.util.PGInterval.getWholeSeconds() at
java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLIntervalSecondJdbcType.<clinit>(PostgreSQLIntervalSecondJdbcType.java:74)
... 17 more
00:50:49,307 ERROR [org.jboss.as.controller.management-operation]
(Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed -
address: ([("deployment" => "servlet-0.0.1-SNAPSHOT.war")]) -
failure description: {"WFLYCTL0080: Failed services" =>
{"jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary"" =>
"java.lang.ExceptionInInitializerError Caused by:
java.lang.ExceptionInInitializerError Caused by:
java.lang.RuntimeException: Could not initialize
PostgreSQLPGObjectJdbcType Caused by: java.lang.NoSuchMethodException:
org.postgresql.util.PGInterval.getWholeSeconds()"}} 00:50:49,360 INFO
[org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010:
Deployed "servlet-0.0.1-SNAPSHOT.war" (runtime-name :
"servlet-0.0.1-SNAPSHOT.war") 00:50:49,361 INFO
[org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183:
Service status report WFLYCTL0186: Services which failed to start:
service jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
java.lang.ExceptionInInitializerError WFLYCTL0448: 11 additional
services are down due to their dependencies being missing or failed
00:50:49,408 INFO [org.jboss.as.server] (Controller Boot Thread)
WFLYSRV0212: Resuming server 00:50:49,410 ERROR [org.jboss.as]
(Controller Boot Thread) WFLYSRV0026: WildFly Preview 27.0.0.Alpha5
(WildFly Core 19.0.0.Beta15) started (with errors) in 9738ms - Started
412 of 658 services (13 services failed or missing dependencies, 362
services are lazy, passive or on-demand) - Server configuration file
in use: standalone.xml
I found the solution, I had PostgreSQL dependencies in my pom maven.This is the code added.
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.postgres</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
NB : org.postgres => the name of my module Postgres previously define in widfly.
I am deploying a simple web application to WildFly 10 from NetBeans to try and teach myself Java EE. However, I get the following error when trying to run a jpql query from NetBeans:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named WebApplication1PU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
This is despite the fact that I have defined a persistence provider. This is 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="WebApplication1PU" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/jboss/db</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2012Dialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
When I test my datasource in WildFly it works:
My JPA Subsystem's default datasource is configured as java:/jboss/db
I have it listed as a persistence unit in WildFly:
I am using JTDS driver for MS SQL Server and I do get this error on startup of the server that I can't get rid of:
10:33:07,600 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "JTDS")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [net.sourceforge.jtds]"
However, as I said, testing the datasource works, so this shouldn't matter. Can anyone help me?
As a comment mentioned, it's saying Wildfly cannot find the provider module.
Download: https://sourceforge.net/projects/jtds/files/jtds/1.3.1/jtds-1.3.1-dist.zip/download - which is the jtds JDBC driver,
and install it into the /modules directory of wildfly.
You can launch the ./jboss-cli.sh to install modules.
See: JTDS module under WildFly (JBoss)
Give a bit more insight into it.
This URL: http://www.mastertheboss.com/jboss-server/jboss-datasource/configuring-a-datasource-with-postgresql-and-jboss-wildfly
Has how to install postgres jdbc drivers into wildfly, but it's effectively the same process for other JDBC drivers, just package name change etc.
In persistence-unit properties you are missing the following
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="dbroot"/>
<property name="hibernate.connection.password" value="password"/>
I have a problem with starting a jpa bundle inside ServiceMix. The problem occurs when using EntityManager injection, while injection of an EntityManagerFactory works fine. Any idea what's wrong?
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="MyUnit" transaction-type="JTA">
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/oracleds)</jta-data-source>
<class>sandbox.MyEntity</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>
blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
>
<bean id="MyDAO" class="sandbox.dao.impl.MyDAOImpl">
<tx:transaction method="*" value="Required" />
<jpa:context property="em" unitname="MyUnit" />
<!--<jpa:unit property="emf" unitname="MyUnit" />-->
</bean>
<service ref="MyDAO" interface="sandbox.dao.MyDAO" />
</blueprint>
Deploying the bundle fails with the following exception:
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:685)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:378)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:276)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:245)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:235)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[12:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[12:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[12:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[12:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[12:org.apache.aries.util:1.1.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1299)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)[org.apache.felix.framework-4.4.1.jar:]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]
Caused by: java.lang.NoClassDefFoundError: javax/persistence/criteria/CriteriaUpdate
at java.lang.Class.getDeclaredMethods0(Native Method)[:1.6.0_45]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)[:1.6.0_45]
at java.lang.Class.privateGetPublicMethods(Class.java:2556)[:1.6.0_45]
at java.lang.Class.getMethods(Class.java:1412)[:1.6.0_45]
at org.apache.aries.blueprint.utils.ReflectionUtils.doGetPublicMethods(ReflectionUtils.java:146)
at org.apache.aries.blueprint.utils.ReflectionUtils.getPublicMethods(ReflectionUtils.java:130)
at org.apache.aries.blueprint.utils.ReflectionUtils.getLifecycleMethod(ReflectionUtils.java:114)
at org.apache.aries.blueprint.container.BeanRecipe.getDestroyMethod(BeanRecipe.java:634)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:812)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:933)
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_45]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[17:org.apache.aries.blueprint.core:1.4.1]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:681)[17:org.apache.aries.blueprint.core:1.4.1]
... 18 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.criteria.CriteriaUpdate not found by org.apache.geronimo.specs.geronimo-jpa_2.0_spec [202]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_45]
at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1397)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1577)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1507)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_45]
... 41 more
MANIFEST.MF imports:
Import-Package: javax.persistence;version="[1.1,2)",org.osgi.service.blueprint;version="[1.
0.0,2.0.0)"
Karaf bundles providing javax.persistence package:
karaf#root> packages:exports | grep javax.persistence
202 javax.persistence; version=1.1.0
202 javax.persistence.criteria; version=1.1.0
202 javax.persistence.metamodel; version=1.1.0
202 javax.persistence.spi; version=1.1.0
202 javax.persistence; version=2.0.0
202 javax.persistence.criteria; version=2.0.0
202 javax.persistence.metamodel; version=2.0.0
202 javax.persistence.spi; version=2.0.0
karaf#root> osgi:info 202
You are about to access system bundle 202. Do you wish to continue (yes/no): yes
Apache Geronimo JSR-317 JPA 2.0 Spec API (202)
Please check your classpath dependencies: javax.persistence.criteria.CriteriaUpdate NoClassDefFoundError was added with JPA 2.1. But according to persistence.xml JPA 2.0 is used in your application.
Edit:
Aries with version >= 1.0.0 depend on JPA 2.1, see its pom.xml file here, and you should update the MANIFEST.MF imports accordingly.
I can not build my entity manager factory and the error I get is "chosen transaction strategy requires access to the JTA Transaction Manager". Can anyone advise what i have to configure to get past this? FYI I'm using Jboss 6, no spring.
Here is my persistance.xml
<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="AvengersPU" transaction-type="JTA">
<jta-data-source>java:/jdbc/thor_ds</jta-data-source>
<class>avenger.Grouptable</class>
<class>avenger.MyUser</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
Here is partial stacktrace...
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: AvengersPU] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) [:3.6.6.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) [:3.6.6.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) [:1.0.0.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) [:1.0.0.Final]
at avenger.Utils.getEntityManager(Utils.java:49) [:]
at avenger.UserBean.updateUserList(UserBean.java:136) [:]
at avenger.UserBean.startup(UserBean.java:43) [:]
... 68 more
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:390) [:3.6.6.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) [:3.6.6.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906) [:3.6.6.Final]
... 74 more
Full stack trace is here: http://pastebin.ca/2166417
Here is an non ideal answer which I will use in the meanwhile.
specify a non jta datasource:
<non-jta-data-source>java:/jdbc/thor_ds</non-jta-data-source>
change transaction type from JTA to RESOURCE_LOCAL
<persistence-unit name="AvengersPU" transaction-type="RESOURCE_LOCAL">
Here is a discussion on the subject:
I am using OpenJPA in cxf(jax-rs) + Struts 2. No external transaction manager. Why am I getting "Can only perform operation while a transaction is active."?
My persistence.xml is like this:
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="myPU"
transaction-type="RESOURCE_LOCAL">
<class>com.bb.bba.entity.Advertisement</class>
<class>com.bb.bba.entity.Poi</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="openjpa.ConnectionURL" value="jdbc:derby://localhost:1527/bba;create=true" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<property name="openjpa.ConnectionUserName" value="APP" />
<property name="openjpa.ConnectionPassword" value="asdasd" />
<property name="openjpa.Log" value="SQL=TRACE"/>
</properties>
</persistence-unit>
</persistence>
I am getting the following error.
35692 2012-06-02 03:50:57,847 DEBUG [http-33791-1] resolver.DefaultTraversableResolver.initJpa (DefaultTraversableResolver.java:77) - Found javax.persistence.PersistenceUtil on classpath.
35729 2012-06-02 03:50:57,884 DEBUG [http-33791-1] resolver.DefaultTraversableResolver.initJpa (DefaultTraversableResolver.java:91) - Instantiated an instance of org.apache.bval.jsr303.resolver.JPATraversableResolver.
35755 2012-06-02 03:50:57,910 TRACE [http-33791-1] jsr303.DefaultMessageInterpolator.loadBundle (DefaultMessageInterpolator.java:189) - ValidationMessages not found by thread local classloader
35755 2012-06-02 03:50:57,910 TRACE [http-33791-1] jsr303.DefaultMessageInterpolator.loadBundle (DefaultMessageInterpolator.java:189) - ValidationMessages not found by validator classloader
35756 2012-06-02 03:50:57,911 DEBUG [http-33791-1] jsr303.DefaultMessageInterpolator.getFileBasedResourceBundle (DefaultMessageInterpolator.java:176) - ValidationMessages not found. Delegating to org.apache.bval.jsr303.ValidationMessages
35778 2012-06-02 03:50:57,933 DEBUG [http-33791-1] xml.ValidationParser.parseXmlConfig (ValidationParser.java:88) - No META-INF/validation.xml found. Using annotation based configuration only.
646 myPU INFO [http-33791-1] openjpa.Runtime - OpenJPA dynamically loaded a validation provider.
922 myPU INFO [http-33791-1] openjpa.Runtime - Starting OpenJPA 2.1.1
1703 myPU INFO [http-33791-1] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.DerbyDictionary".
11326 myPU WARN [http-33791-1] openjpa.Enhance - Creating subclass for "[class com.bb.bba.entity.Poi, class com.bb.bba.entity.Advertisement]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
Here I am
...... nonfatal user error>
org.apache.openjpa.persistence.TransactionRequiredException: Can only
perform operation while a transaction is active.
at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(BrokerImpl.java:4658)
at org.apache.openjpa.kernel.DelegatingBroker.assertActiveTransaction(DelegatingBroker.java:1386)
at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:661)
at com.bb.bba.dao.MyDao.createPoi(MyDao.java:21)
at com.bb.bba.services.Service.createPoi(POIService.java:36)
You will have to open a transaction before you can perform operations on the EntityManager. That's expected behavior. You will have find some transaction strategy for your application. So you have to decide which component opens transactions (especially on which layer) and how it is done (declarative or programmatic).
What other frameworks are you using? If you are for example also using Spring, you can very easily manage transactions using Spring's declarative transaction management support.
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/transaction.html
The problem is solved. I was using resource_local which means I am responsible for the transaction. Adding em.getTransaction.begin solved the issue.