Persistence unit missing dependencies migrating from JBoss EAP 6.4 to 7.0 - jboss

I have an application that must run on both JBoss EAP 6.4 and 7.0. The application uses EJB entity beans which are no longer supported on JBoss EAP 7 so the entity beans are being migrated to use JPA entities as described in the JBoss migration guide. The application deploys and works fine on 6.4 but fails to deploy with "missing dependencies" error on 7.0. I've seen alot of issues where the missing dependency was the datasource but that doesn't seem to be the case here. The datasource isn't mentioned at all in the missing dependencies error. I can see in the logs the persistence.xml file is being parsed and the jndi bindings added for the session beans before the deployment fails.
I have an EAR file that contains multiple war and ejb jar files. The application I'm having an issue with consists of an ejbModule.jar which contains the persistence.xml file and entity classes, and a webModule.war file with taglib classes that reference the entity classes contained in ejbModule.jar.
The structure of the EAR file is outlined below:
MyEAR.ear
- ejbJar.jar
- webApp1.war
- webApp2.war
- ejbModule.jar (contains persistence.xml and entity classes)
-- META-INF/persistence.xml
- webModule.jar (taglib classes have dependency on entity classes from ejbModule.jar)
- META-INF
persistence.xml: (replaced class names, datasource name, persistence-unit name)
<persistence version="2.0" xmlns:per="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="myPU">
<class>org.MyEntity1</class>
<class>org.MyEntity2</class>
<jta-data-source>java:/MyDataSource</jta-data-source>
<properties>
<property name="jboss.entity.manager.jndi.name" value="java:/myPU"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/myPU"/>
</properties>
</persistence-unit>
It's difficult to post the error message as it's got hundreds of lines of "missing dependencies" for class names and application names that I can't share and by the time I replace them all I don't feel it would be of much use. But there are entries like:
"jboss.naming.context.java.comp.MyEAR.ejbModule.MyEntity1.InAppClientContainer is missing [jboss.naming.context.java.comp.MyEAR.ejbModule.MyEntity1]",
However there also entries like:
"jboss.deployment.subunit.\"MyEAR.ear\".\"webApp1.war\".component.\"org.taglib.MyTagLibClass\".START is missing [jboss.persistenceunit.\"MyEAT.ear/ejbModule.jar#myPU\"]"
I can see from the DEBUG logging for org.jboss.as.jpa that JBoss looks to be adding dependencies on the persistence unit for all taglib classes in all war files in the ear. Only the webModule.war needs to use the persistence unit.
2017-12-07 15:37:13,808 DEBUG [org.jboss.as.jpa] (MSC service thread 1-2) Adding dependency on PU service service jboss.persistenceunit."MyEAR.ear#myPU" for component org.taglib.MyTagLibClass
When I move the persistence.xml file to the META-INF directory of the EAR the application deploys and works fine on JBoss EAP 7.0. However, this isn't an ideal solution as the EAR file is built dynamically and could contain custom applications that I have no control over.
I've tried various other structures to try and get this working but haven't found anything else that works.
Any ideas how to get this working on JBoss EAP 7.0?

There are unnecessary entries in your persistence.xml
You just need this
<persistence version="2.0" xmlns:per="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="myPU">
<jta-data-source>java:/MyDataSource</jta-data-source>
</persistence-unit>
Because the entities will be found automatically relative to persistence.xml
Please try this and if doesn't help please post as much of the server.log as you can.
Another idea could be to ask the RedHat support as you use EAP I assume that you have subscriptions containing support.

Related

Class name is wrong or classpath is not set ERROR in Netbeans with Glassfish 5 server and JPAs

I have a Web Application in Netbeans 11 (with JDK 8 installed), I have added the dependencies for mysql-connector-java-8.0.15.jar and I have generated the JPAs from my DB.
No error while building it.
But when I try to run it, the Glassfish server give me these errors (pastebin link).
This is my persistence.xml, that I set accordingly, is:
<?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="InvoicesPU" transaction-type="JTA">
<jta-data-source>java:app/Invoices</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
And in my java class I call it by:
#Stateless
public class InvoiceEJB implements InvoiceEJBLocal {
#PersistenceContext(unitName = "InvoicesPU")
EntityManager em;
...
em.someMethod();
For completeness, I have no error during the compilation phase!
Anyone know how to solve it?
After some research I solved it in this way:
taking inspiration from a similar problem, I created the Connection Pool and the Resource in the Glassfish Admin Console as suggested by devmind following this.
I removed as dependency the mysql-connector-java-8.x.x.jar and I added the mysql-connector-java-5.x.x.jar
In the persistence.xml I set the JNDI name for the tag jta-data-source
And everything goes as expected!
I don't know how to make everything work with the latest version of the MySQL Connector but, at least, in this way my Web Application works.
EDIT: for latests versions of mysql-connector, as devmind has suggest you should set MysqlDataSource: from com.mysql.jdbc.jdbc2.optional.MysqlDataSource to com.mysql.cj.jdbc.MysqlDataSource as reported here.
I hope it's useful to someone else.
Try to put your JDBC driver jar to Glassfish domain's lib folder. I usually store them in lib/ext.
I do not remember if I got this info from some other post or from the Glassfish user manual but it solves the issue mentioned for me, i.e.: Class name is wrong or classpath is not set ERROR with Glassfish 5 or Payara server. I'm using Payara Server 5.2022.3 currently.
Add the latest connector j to your server/your_domain; in my case it is domain1 and this is the script after I cd to /bin:
C:\Program Files\payara-web-5.2022.3\payara5\bin>asadmin add-library --type app "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-j-8.0.31.jar"
Where quoted string is the path where I keep my connector j.

EAR application works on Websphere8.5 but refuses to work on Websphere liberty 16.0.0.4

I get in inheritance EAR application which I need to continue to develop. The problem that I can't cause it work on Websphere Liberty 16.0.0.4 while on Websphere Application Server Full Profile 8.5 it works fine. Unfortunately or (fortunately :) ) my working station is Macbook Pro, and WAS Full Profile can't be installed on OSX (can't find links right now, but have done some search and find enough evidences for it) so I need to use VirtualBox with Linux or try to run this app on Liberty.
The latest solution doesn't work so well for me, I get the following error:
[ERROR ] CWWJP0012E: The persistence unit name is not specified and
a unique persistence unit is not found in the BigEnterpriseAppEAR
application and BigEnterpriseAppEJB.jar module. [ERROR ] CWWJP0029E:
The server cannot find the persistence unit in the
BigEnterpriseAppEJB.jar module and the BigEnterpriseAppEAR
application. [ERROR ] CWNEN0035E: The java:comp/env/BigEnterpriseApp
reference of type javax.persistence.EntityManager for the DataProvider
component in the BigEnterpriseAppEJB.jar module of the
BigEnterpriseAppEAR application cannot be resolved. [ERROR ]
CNTR0020E: EJB threw an unexpected (non-declared) exception during
invocation of method "getDataByOwner" on bean
"BeanId(BigEnterpriseAppEAR#BigEnterpriseAppWEB.war#DataAPI, null)".
Exception data: javax.ejb.EJBTransactionRolledbackException: nested
exception is: javax.ejb.EJBException: The
java:comp/env/BigEnterpriseApp reference of type
javax.persistence.EntityManager for the DataProvider component in the
BigEnterpriseAppEJB.jar module of the BigEnterpriseAppEAR application
cannot be resolved.
The app is pretty simple EAR = JPA + EJB + WAR
I don't know which configuration files would be helpful, so just write in a comments what to post and I will do it.
Thank you in advance.
UPDATE 1:
server.xml file:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>localConnector-1.0</feature>
<feature>servlet-3.1</feature>
<feature>ejbLite-3.1</feature>
<feature>jndi-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>ssl-1.0</feature>
<feature>jpa-2.0</feature>
<feature>cdi-1.0</feature>
</featureManager>
<basicRegistry id="basic" realm="BasicRealm">
<!-- <user name="yourUserName" password="" /> -->
</basicRegistry>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<library id="DB2JCC4Lib">
<fileset dir="/Users/anatoly/developer/sql_drivers" includes="*.jar"/>
</library>
<dataSource id="db2_slc" jndiName="jdbc/BEADB" type="javax.sql.DataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<properties.db2.jcc databaseName="beadb" password="********" portNumber="50000" serverName="db2server" user="db2username"/>
</dataSource>
<keyStore id="defaultKeyStore" password="******"/>
<enterpriseApplication id="BigEnterpriseAppEAR" location="BigEnterpriseAppEAR.ear" name="BigEnterpriseAppEAR"/>
</server>
persistence.xml file, located in BigEnterpriseAppJPA > src > META-INF > persistence.xml
in packaged EAR persistence.xml located in BigEnterpriseAppEAR -> BigEnterpriseAppJPA.jar -> META-INF -> 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="BigEnterpriseApp">
<jta-data-source>jdbc/BEADB</jta-data-source>
<class>com.bea.entities.System</class>
<class>com.bea.entities.Data</class>
<class>com.bea.entities.User</class>
<class>com.bea.entities.Group</class>
<properties>
<property name="openjpa.jdbc.Schema" value="BEADB" />
<property name="openjpa.ConnectionRetainMode" value="transaction" />
</properties>
</persistence-unit>
</persistence>
[ERROR ] CWWJP0012E: The persistence unit name is not specified and a unique persistence unit is not found in the BigEnterpriseAppEAR application and BigEnterpriseAppEJB.jar module.
This would imply your persistence.xml roots are not at the legal locations defined by the JPA spec, section 8.2:
In Java EE environments, the root of a persistence unit must be one of the following:
an EJB-JAR file
the WEB-INF/classes directory of a WAR file[87]
a jar file in the WEB-INF/lib directory of a WAR file
a jar file in the EAR library directory
an application client jar file
NOTE: Java Persistence 1.0 supported use of a jar file in the root of the EAR as the root of a
persistence unit. This use is no longer supported. Portable applications should use the EAR
library directory for this case instead
Your setup seems to be trying to use #4?
BigEnterpriseAppEAR -> BigEnterpriseAppJPA.jar -> META-INF -> persistence.xml
BigEnterpriseAppJPA.jar should be placed inside your EAR library directory. I believe this will be BigEnterpriseAppEAR/lib by default, but you can configure this with your /META-INF/application.xml in the EAR
Also note, that the persistence-unit name must be unique. Make sure that all persistence-unit names are not using the same name.

Websphere v8.0.0.6 WASX7017E, ADMA0209E Application exception while Deployment of EJB 2.0 EAR

I have the following problem with WebSphere 8.0.0.6 and no solution is found on the web. I hope anyone can help with this and this will help someone else with this problem.
Error Description:
Error #1 (while installing application):
WASX7017E: Exception received while running file /tmp/wsant3816346180883063201jacl;
exception information:com.ibm.websphere.management.application.client.AppDeploymentException:
com.ibm.websphere.management.application.client.AppDeploymentException
Following Error:
ADMA0209E: Enterprise JavaBeans (EJB) module ServerEJB.jar contains the following
container-managed persistence (CMP) or bean-managed persistence (BMP) :
... (list of all entities)
Explanation:
I generate an EAR with an EJB 2.0 component/project. Up to now I have deployed this EAR within WAS 6.1 successfully, but with WAS 8 it doesn't deploy anymore.
I have the necessary bind-ejbjar.xmi, even in the new format - converted with the script from IBM.
Questions:
WAS 8 still seems to know that there exists a EJB 3 component in the EAR - the question is WHY?
What is the minimum requirement for a EAR/EJB-Module to deploy in WAS 8 - there must be big changes?
Are there more bind-files to be included?
Thanks for help
UPDATE:
So obviously there are prerequisites to declare a package as EJB2.x.
See IBM-HelpCenter:
IBM WebSphere info for developers DE
But I fullfill all of this two prerequisites.
How do I have to package the jar for Websphere 8 to make it acceptable as an EJB2.x?
http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.zseries.doc%2Fae%2Frejb_consid.html&lang%3Dde
The solution was achieved by upgrading to version 2.1 ejb, because there the "version" attribute is allowed and this is required by WebSphere to recognize a non-EJB 3.0 version.
This means that an EJB 2.0 version can not work, since the above tag is not allowed in the ejb-jar_2_0.dtd. Maybe a
<cmp-version>2.x</cmp-version>
could help here, but I didn't tested it.
The conversion of the header of ejbjar.xml brought success:
from 2.0 (ejb-jar_2_0.dtd):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<!-- EJB-jar file declaration -->
<ejb-jar id="EJBJar" version="2.0">
<display-name>Overall Bean Definition</display-name>
<enterprise-beans>
<entity id="Dcnotetext">
...
to 2.1 (ejb-jar_2_1.xsd - you need namespaces! ):
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="EJBJar"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<!-- EJB-jar file declaration -->
<display-name>Overall Bean Definition</display-name>
<enterprise-beans>
<entity id="Dcnotetext">
...
No further changes to XMI or XML files were necessary!
Thanks for help!

How to use persistence.xml and hibernate.cfg.xml in JUnit tests via eclipse?

I have been searching for an answer during quite a long time before coming here and ask this question.
My problem is very simple : I cannot run any JUnit test when using the JPA Entity Manager API. It seems that my test is not reading the persistence.xml file.
When I call new Configuration().configure().buildSessionFactory(), it works like a charm but an exception is thrown when calling Persistence.createEntityManagerFactory("myapp") is:
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named myapp at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.myapp.Test01.setUpBeforeClass(Test01.java:22)
My JavaSE project has the following structure :
myapp
++src/main/java
++com.myapp.model
++// My entity classes are here
++src/test/java
++com.myapp
++Test01.java
++src/main/resources
++hibernate.cfg.xml
++META-INF
++persistence.xml
and persistence.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">
<persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"></property>
</properties>
</persistence-unit>
</persistence>
Do you have any idea how to solve this issue ?
Thank you very much for your help.
Put the configuration in src/test/resources/META-INF.
My guess would be that org.hibernate.ejb.HibernatePersistence is not on your classpath. That's not in the main Hibernate jar, it's in the hibernate-entitymanager or some such jar.
A couple of quick experiments would be to do, in the code immediately before the call to Persistence.createEntityManagerFactory():
System.out.println(getClass().getResource("META-INF/persistence.xml"));
And:
System.out.println(Class.forName("org.hibernate.ejb.HibernatePersistence"));
It would also be wise to check that Eclipse is copying your resources; do a Project > Clean and then look in your Eclipse build output directory to see if persistence.xml is where you expect. I have sometimes run into cases where Eclipse doesn't copy resources for some reason or other.

How set jdni.properties on ireport

7.2 with ejbql connection my problem is that when i test the connection, fails because Could not find datasource, in the log says:
Caused by: org.hibernate.HibernateException: Could not find datasource
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
I guees can be the jndi.properties that in the wrong directory, i tried put into java_home/lib but doesn't work
Finally after a lot of work i made the ejbql connection with ireport. Follow this steps to do it!!
1) i'm using jboss 4.2.3, so if you using glashfish or other server, find the libraries that match with the jboss that i'm using
2) You need to find in your jboss directory server/default/lib the follow libraries:
hibernate3.jar
hibernate-entitymanager.jar
jboss-common.jar
hibernate-annotations.jar
ejb3-persistence.jar
jboss.jar
3) copy the libraries previously named and copy your ireport installation directory in this path \Jaspersoft\iReport-3.7.2\ireport\modules\ext and replace it, note that the library call hibernate-common-annotation and jpa.jar need to be erase from that path. You need to do it because this library creates conflicts with hibernate-annotations and ejb3-persistence.jar.
4) get the jar of your project and copy it in your in this example let's called example-core.jar to the installation directory in the path \Jaspersoft\iReport-3.7.2\ireport\libs
5) modify the jar the persistence.xml of your project (in our case "example.jar") and sets with this next properties,
<?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="example" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>/jdbc/example</non-jta-data-source>
<properties>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
</properties>
</persistence-unit>
</persistence>
6)Go to ireport and add the libraries to the classpath, in tools, options in the tab of classpath
7) go to the installation directory of ireport in the path Jaspersoft\iReport3.7.2\ireport\modules open the jar called com-jaspersoft-ireport with winrar or other tool , and go to META-INF/MANIFEST.INF in the part of Class-Path modify the name of the library "hibernate-common-annotation.jar" (renember you erase this library) for the "hibernate-annotations.jar"
8)Go to Jboss_home/server/default/deploy and modify the datasource xml of your project and put this configuration, (renember in this example the project is call "example" and the datasource should be called example-ds.xml)
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/example</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:oracle:thin:#localhost:1521:XE</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>example</user-name>
<password>example</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
Note that the property usa-java-context in false is that allow you to access to the data source outside of the jboss in our case from ireport
9)go to the ireport and add the follow libraries into the ireport classpath
jnp-client.jar
jboss-client.jar
jbossall-client.jar
the database driver in my case ojdbc.jar (for oracle)
jboss-ejb3x.jar
10) sets your jndi.properties and put it into the jar hibernate-entitymanager.jar
11) Now run the jboss, go to ireport and create the ejql connection, in the persistence unit name sets the name that place in the persistence.xml of the jar located in installation directory Jaspersoft\iReport-3.7.2\ireport\libs, in this case the persistence unit name is "example" without the quotes marks
I hope that this help to somebody or someone jeje, i know that's pretty hard, and sorry for my english its not my first language