I just created a simple WAR containing a simple JAX-RS Service, an Stateless EJB and some JPA entities. I'm using WildFly 12.
My WAR structure is the following:
WEB-INF
classes
META-INF
jboss-ds.xml
persistence.xml
compiled classes
My jboss-ds.xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jndi-name="java:/jdbc/shortbox" pool-name="mysql_pool" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/shortbox</connection-url>
<driver>mysql</driver>
<security>
<user-name>admin</user-name>
<password>admin</password>
</security>
</datasource>
</datasources>
My persistence.xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="shortbox-unit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/jdbc/shortbox</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
I also injected the EntityManager in my EJB like this
#PersistenceContext(unitName = "shortbox-unit")
private EntityManager em;
My problem is, that the WAR is not deploying like this and I just can't figure out why.
The Exception during deployment is the following
16:56:07,052 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "api.war" was rolled back with the following failure message:
{
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService",
"jboss.deployment.unit.\"api.war\".component.IssueBean.START",
"jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START",
"jboss.deployment.unit.\"api.war\".WeldStartService",
"jboss.persistenceunit.\"api.war#shortbox-unit\"",
"jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE",
"jboss.naming.context.java.jdbc.shortbox",
"jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator",
"jboss.deployment.unit.\"api.war\".ee.ComponentRegistry",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START",
"jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START",
"jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START",
"jboss.undertow.deployment.default-server.default-host./api",
"jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService",
"jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator",
"jboss.deployment.unit.\"api.war\".jndiDependencyService",
"jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"api.war\".ee.ComponentRegistry is missing [jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector]",
"jboss.deployment.unit.\"api.war\".component.IssueBean.START is missing [jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator]",
"jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService is missing [jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".ee.ComponentRegistry]",
"jboss.deployment.unit.\"api.war\".CdiValidatorFactoryService is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START is missing [jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator]",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START is missing [jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator]",
"jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator, jboss.deployment.unit.\"api.war\".jndiDependencyService]",
"jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".WeldStartService is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService]",
"jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService]",
"jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".moduleDeploymentRuntimeInformationStart is missing [jboss.deployment.unit.\"api.war\".component.IssueBean.START]",
"jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE is missing [jboss.naming.context.java.jdbc.shortbox]",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator]",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em is missing [jboss.persistenceunit.\"api.war#shortbox-unit\"]",
"jboss.undertow.deployment.default-server.default-host./api is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START, jboss.deployment.unit.\"api.war\".WeldStartService, jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START]",
"jboss.deployment.unit.\"api.war\".WeldEndInitService is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START]",
"jboss.deployment.unit.\"api.war\".jndiDependencyService is missing [jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em]",
"jboss.deployment.unit.\"api.war\".deploymentCompleteService is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.undertow.deployment.default-server.default-host./api, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START]",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]",
"jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator, jboss.deployment.unit.\"api.war\".jndiDependencyService]",
"jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator]",
"jboss.persistenceunit.\"api.war#shortbox-unit\" is missing [jboss.naming.context.java.jdbc.shortbox, jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE]",
"jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]"
]
}
When I remove the jboss-ds.xml and configure the persistence.xml to use my db everything is deploying fine - but the application is using the exampleDS, because I have not configured any other DS.
What am I doing wrong?
One more important note - I definitly want to manage the DS in my Appliaction, not in the JBoss config.
Thanks in advance!
The solution was simple as ABC... The jboss.xml must be placed in the WEB-INF root and not in the META-INF.
Related
My Java EE application cannot find tables. I am using WildFly (as the application server) and H2 (as the DB, in the embedded mode).
The error is:
org.h2.jdbc.JdbcSQLException: Table "MY_TABLE" not found
Look at my table creation:
create table "MY_TABLE" (
-- ...
);
See how my entity is defined:
#Entity
#Table(name = "MY_TABLE")
public class MyTable {
// ...
}
This is how I call JPA (this causes the exception):
#PersistenceContext
private EntityManager entityManager;
// ...
entityManager.find(MyTable.class, 1);
My persistence.xml is:
<persistence-unit name="myapp" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/myappDS</jta-data-source>
</persistence-unit>
And the standalone.xml in my WildFly:
<datasource jndi-name="java:jboss/datasources/myappDS" pool-name="myappDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:~/myapp;SCHEMA=PUBLIC</connection-url>
<driver>h2</driver>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
Everything looks good so why the exception? Do I need to flush something? Or set schema somewhere?
If I configure another datasource (having the same DB structure) in WildFly (for example Postgres), everything works fine. That would mean that the datasource configuration is the place causing the error.
(Yes, I am totally sure the DB is not empty and the connection URL is correct as I have tried it from an SQL client.)
Are you running the application as a different user than you are testing to connect with? In that case the the ~ in the connection path will resolve to different home folders, and thus different databases.
Otherwise I would suggest connecting with the Shell in the h2 jar file and run show tables to verify that the table exists and with the correct casing. Start the shell by running:
java -cp h2*.jar org.h2.tools.Shell
Where do you store your script for the table creation? Is it in classpath of the application?
In my test setup I let hibernate generate the tables on startup (and dropping it on shutdown) and using an import.sql script for the test-data generation, which is in the folder src/main/resources.
<persistence-unit name="myapp" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/myappDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
I am trying to configure a PostgreSQL datasource in Wildfly 10 Application Server on Mac OS. I am doing what the instructions prescribe. I have created an order:
/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main.
In this order I have put the JDBC driver:
postgresql-9.3-1104.jdbc4.jar
and I have created a module.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>
<resources>
<resource-root path="postgresql-9.3-1104.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
In the standalone.xml file I have created the datasource under datasources:
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true"
use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/testdb</connection-url>
<driver>postgresql</driver>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
</validation>
</datasource>
and drivers as:
<drivers>
<driver name="postgresql" module="org.postgresql">
<datasource-class>org.postgresql.Driver</datasource-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
However it is impossible the datasource is not installed and when I start the server I get the message (error):
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "PostgresDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
"jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]"
]
}
[org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "PostgresDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.jdbc-driver.postgresql",
"jboss.jdbc-driver.postgresql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
"jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]",
"org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]"
]
}
It seems, that wildfly maybe does not find the module. Any ideas what causes this problem? Is anything wrong in my configuration?
I'd like to recommend a change to your process. While you certainly can do this by hand, if you script this you can do it again with repeatability.
This is dependent on the jboss-cli.sh. I have a script that looks like:
embed-server --std-out=echo --server-config=standalone.xml
batch
module add --name=org.postgres --resources=/tmp/postgresql-42.0.0.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources/data-source=myDataSource/:add(connection-url=jdbc:postgresql://localhost:5432/thedatabasename,driver-name=postgres,jndi-name=java:/jdbc/myDataSource,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=theDatabasePassword,user-name=theDatabaseUsername)
run-batch
This is run with:
bin/jboss-cli.sh --file=/path/to/file/wildflyconf.cli
The script starts by using the "embed-server" command so that your Wildfly instance does not need to be running. Then it starts a batch of commands to run as one unit.
The important part is that we create the module via the command line. You will have to put the PostgreSQL jar somewhere but other than that the script takes care of creating all of the needed files under "modules".
Next, we add the JDBC driver and then we create a Datasource based on the driver.
The advantage of a script is that you can check this into your source code control system and anyone can run it. It reduces the possibility of a typo and you don't need to manually create and modify files.
Just a thought. Having a repeatable process that your development team can use is always a useful thing.
You are defining your Driver class as a Datasource class :
<datasource-class>org.postgresql.Driver</datasource-class>
please use the correct element:
<driver-class>org.postgresql.Driver</driver-class>
just like #stdunbar showed you in his CLI command :
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
in your file module.xml in the 2nd line change
<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>
to
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
the ' " ' may be the problem in your module.xml
Set the following system properties in standalone.xml and it should work fine:
-Dorg.kie.server.persistence.dialect=org.hibernate.dialect.PostgreSQLDialect
-Dorg.kie.server.persistence.ds=java:jboss/datasources/yourDataSource
<system-properties>
<property name="org.kie.server.persistence.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="org.kie.server.persistence.ds" value="java:jboss/datasources/ExampleDS"/>
</system-properties>
I just faced this issue with Wildfly-20.0.1.Final. I resolved it by adding the Postgres module to /Wildfly-20.0.1.Final/modules/org/postgresql/main
So, the solution to this issue is to move the module from
/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main
to
/wildfly-10.1.0.Final/modules/org/postgresql/main
I have inherited a legacy application that initially was built with WebSphere 6.1 and then was migrated to WebSphere 8.0 running with JPA 2.0 and openJPA without issues. We are migrating to WebSphere Liberty for strategic reasons. We first tested on WebSphere Classic 8.5.5.8 and JPA and the entity manger has no issues there. However, on Liberty 8.5.5.8 I get the following exception:
javax.ejb.EJBException: The java:comp/env/com.xxx.xxxx.service.CHServiceBean/em reference of type javax.persistence.EntityManager for the CHServiceBean component in the CHServiceEJB.jar module of the CHServiceEAR application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1493)
.....
[err] Caused by:
[err] javax.ejb.EJBException: The java:comp/env/com.xxxx.xxxx.service.CHServiceBean/em reference of type javax.persistence.EntityManager for the CHServiceBean component in the CHServiceEJB.jar module of the CHServiceEAR application cannot be resolved.
[err] at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1493)
[err] at [internal classes]
I had another EJB injection issue that was resolved through configuration of the binding files, however I am unable to resolve this issue. I have two applications that each have their own EAR files but both run in the same Liberty JVM. Application A runs the front end/UI logic while Application B is the back-end EJB / JPA interfaces. In the project facets the JPA application is set to 2.0 (I wanted 2.1 but based on another thread JPA 2.0 and EJB 3.1 are as high as I can go at the moment...See my other thread topic here -->Eclipse Juno and JPA 2.1 support).
Here is my server.xml file:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>javaee-7.0</feature>
<feature>localConnector-1.0</feature>
<feature>distributedMap-1.0</feature>
<feature>adminCenter-1.0</feature>
<feature>ssl-1.0</feature>
<feature>usr:webCacheMonitor-1.0</feature>
<feature>webCache-1.0</feature>
<feature>ldapRegistry-3.0</feature>
</featureManager>
<!-- Admin Center Config Start -->
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<keyStore id="defaultKeyStore" password="xxxxxx"/>
<basicRegistry id="basic">
<user name="admin" password="xxxxx"/>
<user name="nonadmin" password="xxxxxx"/>
</basicRegistry>
<administrator-role>
<user>admin</user>
</administrator-role>
<remoteFileAccess>
<writeDir>${server.config.dir}</writeDir>
</remoteFileAccess>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<enterpriseApplication id="CHNewCHRDMEAR" location="CHNewCHRDMEAR.ear" name="CHNewCHRDMEAR">
<application-bnd>
<security-role name="AllAuthenticated">
<special-subject type="ALL_AUTHENTICATED_USERS"/>
</security-role>
</application-bnd>
</enterpriseApplication>
<enterpriseApplication id="CHServiceEAR" location="CHServiceEAR.ear" name="CHServiceEAR"/>
<!-- JAAS Authentication Alias (Global) Config -->
<authData id="dbUser" password="{xor}MzhmJT06ajI=" user="dbUser"/>
<!-- JDBC Driver and Datasource Config -->
<library id="DB2JCC4Lib">
<fileset dir="C:\DB2\Jars" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
</library>
<dataSource containerAuthDataRef="dbUser" id="CHTEST2" jndiName="jdbc/nextgen" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<properties.db2.jcc databaseName="CHTEST2" password="{xor}MzhmJT06ajI=" portNumber="60112" serverName="server.com" sslConnection="false" user="dbUser"/>
<containerAuthData password="{xor}MzhmJT06ajI=" user="dbUser"/>
</dataSource>
<dataSource id="CHTEST2_RO" jndiName="jdbc/nextgen_RO" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<properties.db2.jcc databaseName="CHTEST2" password="{xor}MzhmJT06ajI=" portNumber="60112" serverName="server.com" sslConnection="false" user="dbUser"/>
<containerAuthData password="{xor}MzhmJT06ajI=" user="dbUser"/>
</dataSource>
<!-- More in file, but no included...-->
</server>
Here is my persistence.xml file:
<?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_2_0.xsd"
version="2.0">
<persistence-unit name="CHService" transaction-type="JTA">
<jta-data-source>jdbc/nextgen</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="openjpa.jdbc.TransactionIsolation" value="read-uncommitted" /></properties></persistence-unit>
<persistence-unit name="CHServiceRO" transaction-type="JTA">
<jta-data-source>jdbc/nextgen_RO</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="openjpa.jdbc.TransactionIsolation" value="read-uncommitted" />
</properties>
</persistence-unit>
</persistence>
I *believe that we are relying solely on injection to get the context for JPA jndi lookups but that is because I don't see in our code any call to an initial context for any JPA specific JNDI names. Below are my two anotated session beans from the EJB project:
a. The CHService Bean:
#Stateless
#TransactionManagement(TransactionManagementType.CONTAINER)
#Local({ CHServiceLocal.class })
#Remote({ CHServiceRemote.class })
#Interceptors({ CHServiceLog.class })
#Resources({
#Resource(name = "jdbc/nextgen", mappedName = "jdbc/nextgen", authenticationType = AuthenticationType.APPLICATION, shareable = true, type = javax.sql.DataSource.class),
#Resource(name = "services/cache/CHBluepages", mappedName = "services/cache/CHBluepages", authenticationType = AuthenticationType.APPLICATION, shareable = true, type = com.ibm.websphere.cache.DistributedMap.class),
#Resource(name = "services/cache/CHGeneric", mappedName = "services/cache/CHGeneric", authenticationType = AuthenticationType.APPLICATION, shareable = true, type = com.ibm.websphere.cache.DistributedMap.class) })
public class CHServiceBean extends AbstractCHServiceImpl implements
CHService {
#PersistenceContext(unitName = "CHService")
private EntityManager em;
b. The CHServiceRO bean:
#Stateless
#TransactionManagement(TransactionManagementType.CONTAINER)
#Local({CHServiceLocalRO.class})
#Remote({CHServiceRemoteRO.class})
#Interceptors({CHServiceROLog.class})
#Resources({
#Resource(name="jdbc/nextgen_RO", mappedName="jdbc/nextgen_RO", authenticationType=AuthenticationType.APPLICATION, shareable=true, type=javax.sql.DataSource.class),
#Resource(name="jdbc/nextgen", mappedName="jdbc/nextgen", authenticationType=AuthenticationType.APPLICATION, shareable=true, type=javax.sql.DataSource.class),
#Resource(name="services/cache/CHBluepages", mappedName="services/cache/CHBluepages", authenticationType=AuthenticationType.APPLICATION, shareable=true, type=com.ibm.websphere.cache.DistributedMap.class),
#Resource(name="services/cache/CHGeneric", mappedName="services/cache/CHGeneric", authenticationType=AuthenticationType.APPLICATION, shareable=true, type=com.ibm.websphere.cache.DistributedMap.class)
})
public class CHServiceBeanRO implements CHServiceRO {
#PersistenceContext (unitName="CHServiceRO") private EntityManager em;
private CHServiceBase ch;
#PostConstruct
private void init() { ch = new CHServiceBase(em); }
Here is a snippet from the Web.xml of the front-end application calling the JPA application:
<resource-ref id="ResourceRef_1436377001246">
<res-ref-name>jdbc/nextgen</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref id="ResourceRef_1436377001247">
<res-ref-name>jdbc/nextgen_RO</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Based on the post from Gas on this topic: java.lang.ClassCastException,Getting Entitymanager Via JNDI Lookup
I also tried updating the web.xml with the following entries:
<persistence-unit-ref>
<persistence-unit-ref-name>chJPA</persistence-unit-ref-name>
<persistence-unit-name>CHService</persistence-unit-name>
</persistence-unit-ref>
<persistence-unit-ref>
<persistence-unit-ref-name>chJPA_RO</persistence-unit-ref-name>
<persistence-unit-name>CHServiceRO</persistence-unit-name>
</persistence-unit-ref>
and the Bean code with:
#PersistenceContext(name = "chJPA", unitName = "CHService")
and
#PersistenceContext (name="chJPA_RO", unitName="CHServiceRO")
Got the same error just with a different jndi name, ie The java:comp/env/chJPA reference of type javax.persistence.EntityManager for the CHServiceBean com.......etc etc.
Lastly, per this post: Error while accessing EntityManager - openjpa - WAS liberty profile
It seems that maybe I can't have the full JavaEE 7 feature and run JPA 2.0? Please advise!
As in the post you are referring to - you cannot have <feature>javaee-7.0</feature> together with JPA 2.0, as it enables 2.1, thats why you have conflicts.
So you have 2 options:
either use Java EE7 and JPA 2.1
or just enable required Java EE 6 features and then use JPA 2.0
Since you are migrating from WAS 8.0, which doesn't support Java EE7 for now, easier choice might be to use the second option.
So try to remove javee-7.0 feature, and add ejbLite-3.1 and jpa-2.0 and whatever you need more.
You are correct that you cannot have javaee-7.0 and the JPA 2.0 feature, as it enables the JPA 2.1 feature. So the answer Gas gave is correct.
I just wanted to point out since you said that you do want to go to JPA 2.1 eventually, once you work out your eclipse issues, that you should use the WebSphere Application Server Migration Toolkit to identify application changes needed when migrating from JPA 2.0 to JPA 2.1. The Liberty JPA 2.0 implementation is built on OpenJPA, whereas the JPA 2.1 implemtation is built on EclipseLink. The migration toolkit is downloadable for free on wasdev: https://developer.ibm.com/wasdev/downloads/#asset/tools-WebSphere_Application_Server_Migration_Toolkit
jboss-service.xml:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean name="com.xxx.yyy:service=SomeClass"
code="com.xxx.yyy.SomeClassBean" xmbean-dd="META-INF/config-mbeans.xml" />
</server>
I have jboss-service.xml above and I'm getting this error:
Caused by: java.lang.IllegalStateException: Current state START_ELEMENT is not among the statesCHARACTERS, COMMENT, CDATA, SPACE, ENTITY_REFERENCE, DTD valid for getText()
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.getText(Unknown Source)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.getText(XMLExtendedStreamReaderImpl.java:275)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.unexpectedContent(JBossServiceXmlDescriptorParser.java:638)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.parseMBean(JBossServiceXmlDescriptorParser.java:221)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.readElement(JBossServiceXmlDescriptorParser.java:192)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.readElement(JBossServiceXmlDescriptorParser.java:48)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.service.ServiceDeploymentParsingProcessor.deploy(ServiceDeploymentParsingProcessor.java:96)
... 6 more
Any idea how to fix this? Tried other suggestions, but nothing seems to work.
According to the section 9.6.2 of the JBossAS docs, you need to define your mbean like this:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean code="..." name="...">
</mbean>
</server>
EDIT
After looking at the source code of JBossServiceXmlDescriptorParser.java:221, one understands that the element xmbean-dd is no longer expected on Wildfly 9. Only NAMEand CODE are expected.
Remove that element from your mbean tag and it will work.
I am having problems while starting a sample app on JBoss server 7.0.
Below follow piece of start log:
12:19:10,156 ERROR [org.jboss.as] (MSC service thread 1-7) JBoss AS 7.0.0.Final "Lightning" started (with errors) in 16391ms - Started 207 of 331 services (67 services failed or missing dependencies, 57 services are passive or on-demand)
12:19:10,361 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployment of "crm.war" was rolled back with failure message {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"crm.war\".jndiDependencyService missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\", jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\" ]","jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ContatoDAORemote.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\" ]","jboss.persistenceunit.\"crm.war#crmUnity\" missing [ jboss.naming.context.java.jdbc/CRMDS ]","jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ClienteRemoteDAO.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\" ]"]}
12:19:10,443 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) Stopped deployment crm.war in 82ms
12:19:10,445 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 1) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"crm.war\".jndiDependencyService missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\", jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\" ]","jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ContatoDAORemote.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\" ]","jboss.persistenceunit.\"crm.war#crmUnity\" missing [ jboss.naming.context.java.jdbc/CRMDS ]","jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ClienteRemoteDAO.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\" ]"]}}}
crm-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>CRMDS</jndi-name>
<connection-url>jdbc:hsqldb:file:database/crm</connection-url>
<driver>hsqldb.jar</driver>
<user-name>SA</user-name>
<password></password>
</local-tx-datasource>
</datasources>
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="crmUnity" transaction-type="JTA">
<jta-data-source>java:/CRMDS</jta-data-source>
<class>br.com.crm.model.entities.Cliente</class>
<class>br.com.crm.model.entities.Contato</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.showSql" value="true"/>
</properties>
</persistence-unit>
</persistence>
The main error is:
ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 1) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ClienteRemoteDAO.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\" ]","jboss.deployment.unit.\"crm.war\".component.br/com/crm/model/dao/ContatoDAORemote.START missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\" ]","jboss.deployment.unit.\"crm.war\".jndiDependencyService missing [ jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ContatoDAOBean/emf\", jboss.naming.context.java.module.crm.crm.\"env/br.com.crm.model.dao.ClienteDAOBean/emf\" ]","jboss.persistenceunit.\"crm.war#crmUnity\" missing [ jboss.naming.context.java.java:CRMDS ]"]}}}
Thank you in advance for help me.
This error appears to be the entity manager missing the datasource. Make sure the JNDI name in both the persistence.xml and -ds.xml is the same (e.g. they should both be java:/CRMDS).
Also JBoss AS 7.0.0 is extremely outdated, if you are starting a new project you should use something newer (either Wildfly or JBoss EAP).