I already made some research on Google and SO but could not find a solution.
I am writing a java ee 7 Web application including Omnifaces and Primefaces using Eclipse. When deploying the application to Glassfish 4, I get the following error:
javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager'
The longer part of the stacktrace is
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Error retrieving java:comp/BeanManager [Root exception is java.lang.IllegalStateException: Cannot resolve bean manager]]
at org.omnifaces.util.JNDI.lookup(JNDI.java:87)
at org.omnifaces.config.BeanManager.init(BeanManager.java:76)
at org.omnifaces.config.BeanManager.getReference(BeanManager.java:115)
at org.omnifaces.application.OmniApplication.createConverter(OmniApplication.java:86)
at javax.faces.application.ApplicationWrapper.createConverter(ApplicationWrapper.java:403)
at org.primefaces.config.ConfigContainer.initConfig(ConfigContainer.java:69)
But I highly doubt that the problem is related to Omnifaces, it's more to state that I didn't do any messy call to cause this.
There is a beans.xml in WEB-INF, it's not completely empty.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
<interceptors>
<class>x.y.z.security.SecurityInterceptor</class>
</interceptors>
</beans>
For the discovery-mode=all, I know it is not recommended, but this is due to an issue I found here: https://java.net/jira/browse/GLASSFISH-20667
If you need more information, facets config or the like, I am happy to post it - but as I've run out of ideas where to locate the problem I don't want to post the everything like complete POM, Glassfish, Eclipse, Maven config or all the code.
edit 2014-01-27:
Ok, after I had written my below comment (the one in comments), I got an idea. Can someone maybe check it out/confirm easily? I was able to load the application to GF after recreating a new database. Can eclipselink cause the above? I am using MS SQL Server 2012, and of course I get SQLExceptions and warnings that tables+fks already exist when redploying, but warnings should not fail my application deployment, should they?
<persistence-unit name="xyzPersistenceUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/xyzDS</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
Related
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.
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.
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.
i´m currently trying to set up a test project with GWT, Maven, Neo4j and Spring Data.
I ran into a problem when I try to start the project in development mode in eclipse
I alway get the error
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/data/neo4j]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
This is the part of the application-context.xml which gives the error.
In pom.xml I use
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
</dependency>
But I also had the problem with the 2.0.0.Release version.
I found the same error here http://neo4j.org/nabble/#nabble-td3428668
but no answer is provided or if there is a fix.
Does someone have an idea where the problem is?
What is your setup? I guess there is a classloader problem in that the neo4j namespace XML is sitting in another bundle and not accessible to the requesting bundles classloader. Could you put all the SDN jars into one big superbundle to get around this_
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