I'm trying to learn the JPA and Oracle DB. I made a maven ear project with an ejb, shared and a web module. I added a glassfish-resources.xml that contains a jdbc connection pool and a jdbc resource to an Oracle database. I can make it work using the DataSource class and JDBC, but when I add an EntityManager to the EJB class (without using it yet), and add a persistence.xml I get the exception java.lang.ClassNotFoundException: oracle.jdbc.OracleConnection$CommitOption. This class is part of the ojdbc-6.jar downloaded from the oracle site and is in the lib folder of my ear. The jar is also added to the ear's Class-Path in its manifest. I've no idea how to make this work.
Related
We are trying to migrate from websphere application server to websphere liberty profile.
As part of POC we are deploying a sample war with an EJB inside it. We injected the EJB using #EJB inside a restful web service. While calling the web service liberty is throwing NPE. Then i tried using InitialContext to lookup the EJB and its working fine.
Below are the features i enabled
Jaxrs 1.1
Jdbc 4.0
ejbLite 3.1
We are running liberty on java 1.6.
Below is some code snippet
#EJB(beanName="StudentServiceBean")
private StudentServiceBean service;
Inside web service method
service.getStudent(id); // NPE here
Ejb class
#Stateless(name="StudentServiceBean")
public class StudentServiceBean {}
I even tried using #EJB with lookup and then tried with simple #EJB becUse the EJB is a local EJB and packed inside the war module itself
P.S.
I moved the ejb to an ejb module and packed the application as an ear and tried. Still the ejb is not getting injected into the web service.
Then i created a new ejb and injected the new ejb into the existing ejb. The new ejb is injected properly. I think there is some problem with servlet container and the ejb container.
I tried it on liberty woth jee7 features also but still i am facing the same problem.
If the #EJB annotation cannot be resolved to an EJB, then you would have received a failure when the server created an instance of the class containing the #EJB annotation. Since that does not appear to be happening for you, and instead the instance is created fine, just without that field being set, then the server is not scanning your class for annotations or you have the javax.ejb.EJB annotation class packaged as part of your application.
I would recommend checking the following:
Make sure the javax.ejb.EJB class is not being packaged as part of your annotation
Check that the web.xml for your WAR module has a version > 2.4. WAR modules with a version of 2.4 (or earlier) will not be scanned for annotations.
Check that the web.xml does not contain the setting metadata-complete="true". This setting turns off annotation scanning.
JAX-RS 1.1 is part of EE6. The EE6 platform spec does not list JAX-RS endpoints among the EE components supporting injection (Table EE.5-1). I don't think your usage there is portable.
I've an EAR with an EJB and WAR project in it. I use Netbeans and the Maven building tool. In my EJB there is one EJB, a singleton class: http://pastebin.com/f8jXw0TK
Here is a screenshot of my project structure in Netbeans: https://gyazo.com/09e075972279f637de2d4d98fe9a1ac7
When I deploy the EAR or the EJB-JAR in Glassfish (localhost). I get the follow error message:
Error occurred during deployment: Exception while deploying the app [arp-auth-business-1.0] : Invalid ejb jar [arp-auth-business-1.0]: it contains zero ejb. Note: 1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar. 3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log to see whether the annotations were processed properly.. Please see server.log for more details.
I've added a simple stateless bean to the EJB JAR, and then it deployed. But then I saw just the simple stateless bean I created, but not my singleton class.
What could be wrong? The server.log shows the same error I get in Glassfish but with a exception stack from the loader. No error from the singleton class or something like that...
Still trying but can't figure it out. Maybe it's maven? But the jar and war file are in the ear file. And in the jar file there is my singleton class.
Kind regards
I am running my application on mule server. Mule server has there own sets of jars and my application that is running on mule server also has few jars. While working on Spring batch I found that JettisonMappedXmlDriver class exists in my application xstream jar as well as mule server jar as well. This class internally refer MappedXMLOutputFactory class that is in jettision jar which is also in my application but some how I am getting classnotfound error for MappedXMLOutputFactory class. This looks like class-loader issue.
If I add jettision jar in mule server then everything work fine but, I can't add this jar on my production environment. Can some body tell me how do I force to load the class from my application jettision jar file. It looks weird to me as classloader should have load MappedXMLOutputFactory class from jettision jar that is in my application folder like it is doing for other classes.
Please let me know if anybody found such issue.
The Mule application classloader is configurable: http://www.mulesoft.org/documentation/display/current/Classloader+Control+in+Mule
So just configure your application's classloader to first look at the JARs it embeds in /lib before deferring to the Mule System classloader.
You will encounter this issue if you have multiple versions of the same class in differnet jars, albeit with different method signatures. The ClassNotFound Error is usually not the only exception that occurs, you will often see another one before that, typically a "NoSuchMethodException" which forces class loader to unload the offending class.
I would suggest using maven or gradle to assemble your application and then use the dependency:tree target to query version conflicts.
I have a Spring Web MVC project. And, I am trying to Create a Spring Loaded Hibernate Connection in IReport using the existing spring web mvc projects application context.
In IReport, In the Options window, in the ClassPath tab, I have added all the latest Spring jars used by the project. As well as the application context's folder.
But, I am getting the following error while testing the connection
Error Creating bean name 'mySessionFactory' defined in the class path resource spring-hibernate.xml: invocation of init method failed;nested exception is org.hibernate.MappingException: entity class not found.
Has anyone successfully connected using the Spring loaded Hibernate connection in Ireport?
IReport uses internally an outdated Version of Spring(I think it is 2.0.0) so if you have for example Annotated Spring and Hibernate, there is no Chance to get run, because Ireport has a heavy use of Reflections.
So if you try to us a CustomClassLoader, you will hit a wall, because IReport tries to load your also after you give it your Custom DataSource.
I am using JBoss 4.2.3 application server.
I have an EAR that currently contains 2 EJB (EJB 3) jars.
In the main EJB jar I have persistence.xml file with the data source configurations.
From the secondary EJB jar file I can successfully call the the EntityManager and read\write entities that are defined in the main EJB jar that contains the persistence.xml
If I try to put an entity in the secondary EJB jar module and then persist it via the EntityManager that uses the persistence unit from the main EJB I get an exception:
Caused by: org.hibernate.hql.ast.QuerySyntaxException: [ENTITY-CLASS-NAME] is not mapped
The solution I found is to create another persistence.xml in the secondary EJB module and change the persistence unit name.
I am not sure whether what I tried to do is correct? Can you please contribute whether I can have a way to share the same persistence.xml withing multiple EJB modules in the EAR (in a way I can have entities in both EJB modules)?
Put the persistence.xml and entities into a JAR in the top-level lib/ directory of the EAR. This should allow the persistence units to be used by all modules in the EAR.