jBPM6.3+Hibernate4+Tomcat7+JPA2.0Exception: Unable to build EntityManagerFactory - eclipse

I was trying to make this example work for me. Since my jbpm version is 6.3.0.Final, so this solution absolutely won't solve my problem.
My scenario is, firstly, I created a JPA & Dynamic Web Project by using Eclipse Mars1, and copied all the example files into my new project, then modified TaskProcessServlet.java, as shown below, because of the obsoleteness and deprecation of the Runtimepart in original servlet code. When I built my project and ran on independent Tomcat 7.0.64 other than server inside of Eclipse, and jsp showed up without any problem, but when I clicked create Processwhich will fire the TaskProcessServlet, I got an error message:
Error:[PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
Would my postgresql-9.4.1207.jar(for Tomcat8) be a problem? I don't think so because I kept getting same error in Tomcat 8, so I downgrade my Tomcat from 8.0.30 to Tomcat 7.0.64.
I'm able to run jbpm-console from JBOSS both on my Tomcat 8 and 7. Does this jbpm-console interfere my project?
How to tackle this problem?
Any idea would be appreciated, thank you very much.
Software Environment:
Ubuntu 64-bit 14.04
Eclipse Mars1
jBPM 6.3.0.Final
PostgreSQL 9.3(postgresql-9.4.1207.jar)
Hibernate 4.2.21.Final
JPA 2.0
Tomcat 7.0.64
NO Spring
NO Maven
TaskProcessServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String action = request.getParameter("action");
if (action.equals("CreateProcess")) {
/*
UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
ut.begin();
*
* Get the local task service
*
KieSession ksession = JBPMUtil.getSingletonSession();
TaskService taskService = JBPMUtil.getTaskService();
ksession.startProcess("com.autopal.bpmn.sampleHTformvariables",params);
System.out.println(" after start");
//ksession.fireAllRules();
ut.commit();
*/
// create the entity manager factory
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.persistence.jpa");
TransactionManager tm = TransactionManagerServices.getTransactionManager();
// setup the runtime environment
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
.newDefaultBuilder()
.addAsset(ResourceFactory.newClassPathResource("taskexample/SampleHumanTaskFormVariables.bpmn"), ResourceType.BPMN2)
.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, tm)
.get();
// get the kie session
RuntimeManager manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
// start the transaction
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("priority", "High");
params.put("modelNumber", "123");
params.put("quantity", "66");
// perform multiple commands inside one transaction
ksession.startProcess("com.autopal.bpmn.sampleHTformvariables",params);
// commit the transaction
ut.commit();
request.setAttribute("message", "Process Created!");
RequestDispatcher rD = request.getRequestDispatcher("adminuser.jsp");
rD.forward(request, response);
}
...
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="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<mapping-file>META-INF/Executor-orm.xml</mapping-file>
<mapping-file>META-INF/Servicesorm.xml</mapping-file>
<mapping-file>META-INF/TaskAuditorm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
<!-- manager -->
<class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
<class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
<class>org.jbpm.services.task.impl.model.ContentImpl</class>
<class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.DelegationImpl</class>
<class>org.jbpm.services.task.impl.model.EscalationImpl</class>
<class>org.jbpm.services.task.impl.model.GroupImpl</class>
<class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
<class>org.jbpm.services.task.impl.model.NotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
<class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class>
<class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
<class>org.jbpm.services.task.impl.model.TaskImpl</class>
<class>org.jbpm.services.task.impl.model.TaskDataImpl</class>
<class>org.jbpm.services.task.impl.model.UserImpl</class>
<!--BAM for task service -->
<class>org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform"/>
</properties>
</persistence-unit>
Catalina.out
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.password=****, c3p0.numHelperThreads=10, c3p0.maxIdleTime=60, c3p0.testConnectionOnCheckout=true, c3p0.maxStatements=100, hibernate.show_sql=true, hibernate.default_catalog=mybox, hibernate.jdbc.batch_size=50, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.fetch_size=100, c3p0.maxPoolSize=30, c3p0.initialPoolSize=3, hibernate.hbm2ddl.auto=create, hibernate.default_schema=public, hibernate.connection.release_mode=after_transaction, hibernate.connection.username=postgres, c3p0.idleConnectionTestPeriod=900, hibernate.connection.driver_class=org.postgresql.Driver, c3p0.minPoolSize=2, c3p0.preferredTestQuery=select now(), c3p0.acquireIncrement=3, hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect, hibernate.connection.url=jdbc:postgresql://192.168.1.80:5432/mybox}
Feb 05, 2016 3:58:09 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 05, 2016 3:58:10 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: META-INF/JBPMorm.xml
Feb 05, 2016 3:58:10 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: META-INF/Taskorm.xml
Feb 05, 2016 3:58:10 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: META-INF/Executor-orm.xml
Feb 05, 2016 3:58:10 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: META-INF/Servicesorm.xml
Feb 05, 2016 3:58:10 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: META-INF/TaskAuditorm.xml

Thanks Anton Giertli, Thank you for your attention.
I've solved this problem after modifying my server.xml and adding a hibernate.cfg.xml for JPA by referring to here.
But I still had consequential issues that I need to figure out.
Thank you any way.

Related

WFLYCTL0180: Services with missing/unavailable dependencies in Wildfly 26 with EJB SecurityDomain annotation

We've got an application with several web services annotated with #SecurityDomain("our-ws") (I've also tried setting this in jboss-web.xml). For example:
#Stateless
#Interceptors(OurTransactionInterceptor.class)
#WebService(targetNamespace = "...", portName = "AddStuff", serviceName = "AddStuffService")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#WebContext(authMethod = "BASIC", contextRoot = "/service", urlPattern = "/AddStuffService")
#SecurityDomain("our-ws")
public class AddStuffService { ... }
We are upgrading to Wildfly 26, and attempting to use elytron following the example from
WildFly Elytron Security, section 4.1.3. However, on startup, I'm getting an error like:
13 Jan 2023 11:26:01,763 ERROR [management-operation Controller Boot Thread] WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "service.war")]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.security.security-domain.our-ws"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"service.war\".component.AddStuffService.CREATE is missing [jboss.security.security-domain.our-ws]"]
}
In standalone.xml, under <subsystem xmlns="urn:wildfly:elytron:15.1"...> We've got a datasource, which I'll call 'ourDS' (not shown) used by a jdbc-realm, jdbc:
<jdbc-realm name="jdbc">
<principal-query sql="SELECT password FROM CFG_WS_USERS_T WHERE username=?" data-source="evercoreDS">
<clear-password-mapper password-index="1"/>
</principal-query>
<principal-query sql="SELECT roles from CFG_WS_ROLES_T r join CFG_WS_USERS_T u on u.WS_USERS_PK=r.WS_USERS_FK where u.username=?" data-source="ourDS">
<attribute-mapping>
<attribute to="roles" index="1"/>
</attribute-mapping>
</principal-query>
</jdbc-realm>
And a security-domain for those web services:
<security-domain name="our-ws" default-realm="jdbc" permission-mapper="default-permission-mapper">
<realm name="jdbc" role-decoder="groups-to-roles"/>
</security-domain>
So I don't get why jboss.security.security-domain.our-ws is not installed (unless, maybe, it is looking for it in the legacy security configuration.).
How, do I get the SecurityDomain annotation (or the security-domain tag in jboss-web.xml) to refer to the elytron configuration, or why would my security-domain under elytron not be installed?
EDIT: In response to #ehsavoie's comment, I'll note that, per section 4.1.3 of the doc, we also have an http-authentication-factory and application-security-domain:
<http-authentication-factory name="our-ws-http-auth" security-domain="our-ws" http-server-mechanism-factory="global">
<mechanism-configuration>
<mechanism mechanism-name="BASIC">
<mechanism-realm realm-name="our-ws"/>
</mechanism>
</mechanism-configuration>
</http-authentication-factory>
<application-security-domains>
<application-security-domain name="defaultASD" security-domain="ApplicationDomain"/>
<application-security-domain name="our-ws-appsecurity-domain" http-authentication-factory="our-ws-http-auth"/>
</application-security-domains>
(I'm a bit confused by the mechanism-realm realm-name="our-ws", since our-ws is not a security-realm, but a security-domain, but it follows the documentation - again section 4.1.3-- and I also tried using the jdbc security-realm there, with the the same error.)

Liberty class loading issues or problem with hibernate (migrating tomcat app on liberty)?

i have to deploy a multi-module application in ear on Liberty Server 20 in my Eclipse. This application use hibernate as provider jpa2 and Derby client + driver derby-10.12.1.1.jar(as shared fileset). Persistence.xml is configured with non jta.
This is server.xml:
<enterpriseApplication id="rubrica-ear" location="rubrica-ear.ear" name="rubrica-ear"/>
<dataSource jndiName="jdbc/TestappDS" type="javax.sql.ConnectionPoolDataSource">
<properties.derby.client createDatabase="false" databaseName=".rubrica"></properties.derby.client>
<jdbcDriver>
<library>
<fileset dir="C:\programmiMio\java-eclipse\drivers" id="shared"></fileset>
</library>
</jdbcDriver>
</dataSource>
My .rubrica db location is in /usr/home.
Because I dont want to start a server derby on console but automatically, i do taht in a #WebListener class:
#WebListener
public class ReqListener implements ServletContextListener {
static final Logger log = LoggerFactory.getLogger(ReqListener.class);
PrintWriter pw = new PrintWriter(System.out);
private NetworkServerControl derbyserver;
#Override
public void contextInitialized(ServletContextEvent arg0) {
try {
String userHomeDir = System.getProperty("user.home", ".");
String systemDir = userHomeDir + "/.rubrica";
// Set the db system directory and startup Server Derby for incoming connections.
System.setProperty("derby.system.home", systemDir);//il db viene salvato qui
derbyserver = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
derbyserver.start(pw);
log.info("Apache derby settings ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage());
}
}
#Override
public void contextDestroyed(ServletContextEvent arg0) {
if (derbyserver!=null){
...
}
}
When i deploy i get this error
[ERROR] An error occurred in the org.hibernate.ejb.HibernatePersistence persistence provider when attempting to create the entity manager factory of the testapp persistence unit container. The following error occurred: java.lang.NullPointerException
at org.hibernate.engine.jdbc.spi.TypeInfo.extractTypeInfo(TypeInfo.java:128)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:163)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
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.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
at com.ibm.ws.jpa.management.JPAPUnitInfo.createEMFactory(JPAPUnitInfo.java:919)
at [internal classes]
When I debug on Liberty i see that Hibernate classes running before the #WebListener code (this is not the same thing in Tomcat), how can i resolve this issue? Something about class loading settings?
I try derby Embedded instead, but problem still araise again, in server.xml:
<properties.derby.embedded createDatabase="create" databaseName="C:/Users/myuser/.rubrica" shutdownDatabase="false"/>
<jdbcDriver>
<library>
<fileset dir="C:\programmiMio\java-eclipse\drivers" id="shared-libs"/>
</library>
</jdbcDriver>
Thanks
Roberto

javax.ejb.NoSuchEJBException: EJBCLIENT000079 with JBoss 7.1 and Eclipse

I am quite new to JavaEE and tried to get a little Hello World example running (https://ibytecode.com/blog/how-to-create-a-simple-ejb3-project-in-eclipse-jboss-7-1/), but I am stuck with an
Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/HelloWorldSessionBean/HelloWorldBean", view is interface com.ibytecode.business.HelloWorld, affinity is None
It is probably only some beginner's error, but I am lost here.
Here is my source code:
HelloWorld.java
package com.ibytecode.business;
import javax.ejb.Remote;
#Remote
public interface HelloWorld {
public String sayHello();
}
HelloWorldBean.java
package com.ibytecode.businesslogic;
import com.ibytecode.business.HelloWorld;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloWorldBean
*/
#Stateless
public class HelloWorldBean implements HelloWorld {
public HelloWorldBean() {
}
#Override
public String sayHello() {
return "Hello World !!!";
}
}
I created a JBoss 7.1 Server in Eclipse, started and deployed the HelloWorldSessionBean. That seemed to work well:
...
10:23:17,999 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-8) WFLYEJB0473: JNDI bindings for session bean named 'HelloWorldBean' in deployment unit 'deployment "HelloWorldSessionBean.jar"' are as follows:
java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:global/HelloWorldSessionBean/HelloWorldBean
java:app/HelloWorldSessionBean/HelloWorldBean
java:module/HelloWorldBean
...
Here's the client code:
package com.ibytecode.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibytecode.business.HelloWorld;
public class EJBApplicationClient {
public static void main(String[] args) {
InitialContext context = null;
HelloWorld bean = null;
try {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
//properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
context = new InitialContext(properties);
String lookupName = "ejb:/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld";
bean = (HelloWorld) context.lookup(lookupName);
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println(bean.sayHello());
}
}
And I put jboss-ejb-client.properties in the class path:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=admin
remote.connection.default.password=admin
When I run the client as plain Java application, I get this output:
Mär 07, 2019 2:35:57 PM org.wildfly.naming.client.Version <clinit>
INFO: WildFly Naming version 1.0.7.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.wildfly.security.Version <clinit>
INFO: ELY00001: WildFly Elytron version 1.1.7.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.naming.ejb.ejbURLContextFactory <clinit>
INFO: EJBCLIENT000064: org.jboss.ejb.client.naming.ejb.ejbURLContextFactory is deprecated; new applications should use org.wildfly.naming.client.WildFlyInitialContextFactory instead
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 4.0.9.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.naming.remote.client.InitialContextFactory <clinit>
INFO: WFNAM00025: org.jboss.naming.remote.client.InitialContextFactory is deprecated; new applications should use org.wildfly.naming.client.WildFlyInitialContextFactory instead
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.LegacyPropertiesConfiguration configure
INFO: EJBCLIENT000072: Using legacy jboss-ejb-client.properties EJB client configuration
Mär 07, 2019 2:35:57 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.5.4.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.5.4.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.RemotingLegacyConfiguration getConfiguredEndpoint
INFO: EJBCLIENT000070: Using legacy jboss-ejb-client.properties Remoting configuration
Mär 07, 2019 2:35:57 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 5.0.5.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.ElytronLegacyConfiguration getConfiguredAuthenticationContext
INFO: EJBCLIENT000069: Using legacy jboss-ejb-client.properties security configuration
Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/HelloWorldSessionBean/HelloWorldBean", view is interface com.ibytecode.business.HelloWorld, affinity is None
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:567)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.protocol.remote.RemotingEJBClientInterceptor.handleInvocationResult(RemotingEJBClientInterceptor.java:56)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.TransactionPostDiscoveryInterceptor.handleInvocationResult(TransactionPostDiscoveryInterceptor.java:133)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.DiscoveryEJBClientInterceptor.handleInvocationResult(DiscoveryEJBClientInterceptor.java:108)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.NamingEJBClientInterceptor.handleInvocationResult(NamingEJBClientInterceptor.java:78)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:172)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:913)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:177)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:112)
at com.sun.proxy.$Proxy0.sayHello(Unknown Source)
at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:53)
Suppressed: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:327)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:570)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:536)
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:487)
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:433)
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:122)
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:135)
at org.jboss.remoting3.Endpoint.getConnection(Endpoint.java:212)
at org.jboss.ejb.client.legacy.RemotingLegacyConfiguration.getConfiguredEndpoint(RemotingLegacyConfiguration.java:81)
at org.jboss.remoting3.ConfigurationEndpointSupplier$Holder.lambda$static$0(ConfigurationEndpointSupplier.java:58)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.remoting3.ConfigurationEndpointSupplier$Holder.<clinit>(ConfigurationEndpointSupplier.java:45)
at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:84)
at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:40)
at org.wildfly.common.context.ContextManager.getPrivileged(ContextManager.java:282)
at org.jboss.remoting3.Endpoint.getCurrent(Endpoint.java:80)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider.<init>(RemotingEJBDiscoveryProvider.java:92)
at org.jboss.ejb.protocol.remote.RemoteTransportProvider.notifyRegistered(RemoteTransportProvider.java:43)
at org.jboss.ejb.client.EJBClientContext.<init>(EJBClientContext.java:275)
at org.jboss.ejb.client.EJBClientContext$Builder.build(EJBClientContext.java:788)
at org.jboss.ejb.client.ConfigurationBasedEJBClientContextSelector.loadConfiguration(ConfigurationBasedEJBClientContextSelector.java:71)
at org.jboss.ejb.client.ConfigurationBasedEJBClientContextSelector.<clinit>(ConfigurationBasedEJBClientContextSelector.java:52)
at org.jboss.ejb.client.EJBClientContext.getDefault(EJBClientContext.java:109)
at org.wildfly.common.context.ContextManager.getPrivileged(ContextManager.java:282)
at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:798)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:161)
... 3 more
Suppressed: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:327)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:570)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:536)
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:487)
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:433)
at org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:51)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider.getConnectedIdentityUsingClusterEffective(RemotingEJBDiscoveryProvider.java:311)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.lambda$connectAndDiscover$0(RemotingEJBDiscoveryProvider.java:384)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.connectAndDiscover(RemotingEJBDiscoveryProvider.java:384)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.countDown(RemotingEJBDiscoveryProvider.java:468)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt$1.handleFailed(RemotingEJBDiscoveryProvider.java:350)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt$1.handleFailed(RemotingEJBDiscoveryProvider.java:342)
at org.xnio.IoFuture$HandlingNotifier.notify(IoFuture.java:215)
at org.xnio.AbstractIoFuture$NotifierRunnable.run(AbstractIoFuture.java:720)
at org.jboss.remoting3.EndpointImpl$TrackingExecutor.lambda$execute$0(EndpointImpl.java:926)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I put the jboss-client.jar from $JBOSS-HOME/bin/client in the classpath.
Any suggestions what I did wrong?
Thanks a lot!
Edit: Probably, it's worth noting that the NoSuchEJBException occurs because of bean.sayHello(). So, maybe it's not a problem with the lookup, but with the connection?
It seems that your lookupName (JNDI) of HelloWorldBean is wrong. Try this:
java:jboss/HelloWorldBean
ALso you can watch this article and find proper JNDI name of your bean on JBOSS admin page.
How to find JNDI name in JBoss-7?

javax.persistence.PersistenceException: No Persistence provider for EntityManager named Eclipselink_JPA

I'm new to JPA and I'm pretty lost in this.
I created an enterprise project in netbeans to do some tests. Created this persistence unit with the wizard. I added it a JNDI connection that works proper and it's already tested:
<?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="persistencia" transaction-type="JTA">
<jta-data-source>jdbc/nuevaConexion</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
Later, I created a sample entity with some test variables to see how this works:
#Entity
public class Entity1 implements Serializable {
private static long serialVersionUID = 1L;
private String nombre;
private int numero;
/**
* #return the serialVersionUID
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* #param aSerialVersionUID the serialVersionUID to set
*/
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
// setters & getters
Then, tried to make the service CreateEntity1 to give it a try, and try to create a new element on the DB by calling it:
public class CreateEntity1 {
public static void main( String[ ] args ) {
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager( );
entitymanager.getTransaction( ).begin( );
Entity1 ent = new Entity1( );
ent.setId(1);
ent.setNombre("Mi entidad");
ent.setNumero(123);
entitymanager.persist( ent );
entitymanager.getTransaction( ).commit( );
entitymanager.close( );
emfactory.close( );
}
}
... but it doesn't work. I get the following error:
Exception in thread "main" javax.persistence.PersistenceException: No
Persistence provider for EntityManager named Eclipselink_JPA at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at service.CreateEntity1.main(CreateEntity1.java:22)
C:\Users\hp\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53:
Java returned: 1 BUILD FAILED (total time: 0 seconds)
What am I doing wrong?
EDIT: I changed the name of the persistence provider to the good one, but now I'm getting a serious bunch of errors.
EDIT 2: Changed everything to Hibernate type. Still getting a huge error:
Exception in thread "main" Local Exception Stack: Exception
[EclipseLink-30009] (Eclipse Persistence Services -
2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while trying to load
persistence unit at url:
file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence
Services - 2.6.1.v20150605-31e8258):
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing
persistence.xml from URL:
file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/
Internal Exception: (1. El destino de la instrucción de procesamiento
que coincide con "[xX][mM][lL]" no está permitido.) at
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionLoadingFromUrl(PersistenceUnitLoadingException.java:100)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:616)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:500)
at
org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchive(JPAInitializer.java:178)
at
org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:160)
at
org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:141)
at
org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at service.CreateEntity1.main(CreateEntity1.java:22) Caused by:
Exception [EclipseLink-30004] (Eclipse Persistence Services -
2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing
persistence.xml from URL:
file:/C:/Users/hp/Documents/NetBeansProjects/PruebasJ2EE/PruebasJ2EE-ejb/build/classes/
Internal Exception: (1. El destino de la instrucción de procesamiento
que coincide con "[xX][mM][lL]" no está permitido.) at
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:118)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:665)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:614)
... 8 more Caused by: (1. El destino de la instrucción de
procesamiento que coincide con "[xX][mM][lL]" no está permitido.) at
org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.error(XMLExceptionHandler.java:28)
at
org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.fatalError(XMLExceptionHandler.java:34)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:180)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPIData(XMLScanner.java:723)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanPIData(XMLDocumentFragmentScannerImpl.java:1018)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPI(XMLScanner.java:691)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:655)
... 9 more
C:\Users\hp\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53:
Java returned: 1 BUILD FAILED (total time: 0 seconds)
Look at my anwser at my anwser at Simplest working example of Spring Data JPA. To me it was simple enough. Hope it will be as simple to You.
You have missed <provider>... try to add it like this:
<?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="persistencia" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...

JTA not rolling back when deleting cascade fails

Using: Glassfish 3.1.2, EclipseLink.
I have the following three-classes JPA model:
#Entity public class Customer implements Serializable {
#Id private Integer id;
#OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval=true)
private Person person;
[...]
#Entity public class Person implements Serializable {
#Id private Integer id;
[...]
#Entity public class Request implements Serializable {
#Id private Integer id;
#ManyToOne private Person person;
I try to remove a customer with the following strategy (using CMT):
<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="MyPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
<property name="eclipselink.logging.timestamp" value="true"/>
<property name="eclipselink.logging.session" value="false"/>
<property name="eclipselink.logging.thread" value="false"/>
</properties>
</persistence-unit>
[...]
#PersistenceContext(unitName="MyPU")
private EntityManager entityManager;
#Resource private SessionContext context;
[...]
public void delete(Entity object) {
try{
object = this.getEntityManager().merge(object);
this.getEntityManager().remove(object);
} catch (Exception e){
this.context.setRollbackOnly();
}
}
When the Customer object is attached to a Person object that is attached to a Request, the delete cascade of Person fails causing the transaction to rollback, but the Customer is deleted from the database. I receive the following error:
INFO: [EL Fine]: 2012-12-28 10:53:38.1--Connection(27132168)--DELETE FROM CUSTOMER WHERE (ID = ?)
bind => [97]
INFO: [EL Fine]: 2012-12-28 10:53:38.125--Connection(27132168)--DELETE FROM PERSON WHERE (ID = ?)
bind => [111]
INFO: [EL Fine]: 2012-12-28 10:53:38.126--SELECT 1
WARNING: DTX5014: Caught exception in beforeCompletion() callback:
Local Exception Stack:
INFO: [EL Warning]: 2012-12-28 10:53:38.127--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERRO: atualização ou exclusão em tabela "person" viola restrição de chave estrangeira "fk_request_person_id" em "request"
Detalhe: Chave (id)=(111) ainda é referenciada pela tabela "request".
Error Code: 0
Call: DELETE FROM PERSON WHERE (ID = ?)
bind => [111]
Query: DeleteObjectQuery(111)
[...]
SEVERE: javax.ejb.EJBException: Transaction aborted
[...]
So, how can i cancel the customer removal when the cascade deletion fails?
There are two things that possible may go wrong here.
The transaction boundaries are not correctly specified
Maybe due to this, your application server does not issue the BEGIN statement correctly. This would explain that Postgres has a problem, while Oracle does not (it implicitly starts a transaction). Make sure your service methods wear the correct annotations. If everything is fine, maybe
There is a problem with your datasource.
Is it a JTA compatible datasource? Does it use the correct driver for Postgres? Please post your config so that we can check out.
I found an interesting link that may help you as well. It is about Postgres staying in autocommit mode (although when using Spring):
http://archives.postgresql.org/pgsql-jdbc/2007-07/msg00115.php