JBoss7 and Eclipselink, No Persistence provider for EntityManager - eclipselink

I'm having a problem with JBoss 7.02.Final. I'm porting a project from JBoss5.1GA and (outside a fair amount of rewrites in the lookups to support EE6) I'm having a problem registering Eclipselink on the classpath. I've searched around and I see several posts saying this issue is fixed but I can't seem to find a working example.
There's a very high chance I'm doing something wrong as I'm new to EE6 development.
The ear is built as the following
- ProductionEE6
./lib/eclipselink2.*.jar
./lib/javax.persistence.jar
. . .
ProductionEJB.jar
. . .
Production.war
My persistence.xml is:
<?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 persistence_2_0.xsd">
<persistence-unit name="production" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:/ProductionDS</non-jta-data-source>
<class><!-- entities --></class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="eclipselink.target-server" value="JBoss"/>
<!-- A few other properties here -->
</properties>
</persistence-unit>
</persistence>
Everything boots up fine, I see the datasources, I get through security (through a custom DatabaseModule so my data-sources are definitely fine) and when I finally make a call to an EJB I see the following errors:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named production
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at com.danielbchapman.production.entity.DelegateInstance.getEm(DelegateInstance.java:67) [ProductionEJB.jar:]
at com.danielbchapman.production.entity.EntityInstance.getEm(EntityInstance.java:39) [ProductionEJB.jar:]
at com.danielbchapman.production.beans.OptionsDao.<init>(OptionsDao.java:20) [ProductionEJB.jar:]
... 94 more
In regards to that, I'm not using a JTA DataSource so I've been handling the transactions manually. This call is the "DelegateInstance" above with the following code: (where persistenceUnitId is "production" in this case.)
/**
* #return an instance of the entity manager if it isn't there.
*/
public EntityManager getEm()
{
if(manager == null)
{
manager = Persistence.createEntityManagerFactory(getPersistenceUnitId())
.createEntityManager();
}
return manager;
}
What worries me the most is seeing this on the stack:
[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final] Obviously I'm not loading EclipseLink properly. I'm running out of ideas here so if anyone can help I'd be very grateful.

EclipseLink 2.4 will now work with JBoss AS 7.1.1 - tested and working - hth

According to http://dev.dzhokanov.com/?p=8:
Furthermore, this forum thread came to support my hypothesis – http://community.jboss.org/message/623759#623759
In the thread Scott Marlow (JBoss 7/JPA lead developer) admits:
“You are not the only one that wants to use EclipseLink but that is not ready yet. “
As far as I understand, there are some incompatibilities in the EclipseLink JPA implementation that need to be adjusted in order to be compatible with JBoss 7. So, I don’t expect Jboss 7-EclipseLink support soon.
So it might be the case that this is currently not possible at all. But if you find a way, I'd be very interested in it.

Related

EclipseLink internal logging statements go through Log4j2

I want the internal logging statements from EclipseLink (version 2.7.x) to be logged through my Log4j2 setup.
I know there's a bug report on this (https://issues.apache.org/jira/browse/LOG4J2-444) which never got solved. I also know, there is a wiki how to implement an own logger (https://wiki.eclipse.org/EclipseLink/Examples/Foundation/Logging).
Since I think someone must have already addressed this problem (since there should be thousands of EclipseLink + log4j2 setups out there) and come out with a reliable solution, my question would be:
Where can i find it?
I am not sure this solution is the best, but
The library contain EclipseLink logger impelementation for slf4j:
https://search.maven.org/artifact/org.eclipse.persistence/org.eclipse.persistence.extension
You can set it to use in persistence.xml:
<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.slf4j.SLF4JLogger" />
Now you need bridge slf4j -> log4j2:
https://search.maven.org/artifact/org.apache.logging.log4j/log4j-slf4j-impl
And finally log4j2.xml: <Logger name="eclipselink.logging" level="ALL"> ... </Logger>
level="ALL" because what exatly will be logged is configured in persistence.xml e.g. eclipselink.logging.level property an so on:
https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging

jpa-store and hibernate OGM

Issue:
Try to configure infinspan cache with jpa-store and hibernate OGM. I can able to access the infinispan server cache through hotrod client with simple cache store, the configuration is follows,
I have configured following in ..\infinispan-server-8.1.0.CR1\standalone\configuration\standalone.xml and run the server by command ../bin>standalone.bat
<subsystem xmlns="urn:infinispan:server:core:8.1">
<cache-container name="local" default-cache="default" statistics="true">
...
<local-cache name="testCache">
<compatibility/>
</local-cache>
</<cache-container>
<subsystem>
In client side, accessing the cache sucessfully using hotrod client like below code.
Configuration config = new ConfigurationBuilder().addServer().host("127.0.0.1").port(11222).build();
RemoteCacheManager cacheManager = new RemoteCacheManager(config);
RemoteCache<Integer, TestEntity> cache = cacheManager.getCache("testCache");
1. How to configure jpa-store (with load from database and write into database) in standalone.xml?
I have tried with below code in standalone.xml.
<persistence passivation="false">
<jpa-store xmlns="urn:infinispan:config:store:jpa:8.0"
shared="true" preload="true"
persistence-unit="CachePersistenceUnit"
entity-class="TestEntity"
singleton="false"
batch-size="1">
</jpa-store>
</persistence>
Caused by: javax.xml.stream.XMLStreamException: WFLYCTL0198: Unexpected element '{urn:infinispan:server:core:8.1}persistence' encountered
at org.jboss.as.controller.parsing.ParseUtils.unexpectedElement(ParseUtils.java:89)
at org.jboss.as.clustering.infinispan.subsystem.InfinispanSubsystemXMLReader.parseCacheElement(InfinispanSubsystemXMLReader.java:971)
at org.jboss.as.clustering.infinispan.subsystem.InfinispanSubsystemXMLReader.parseLocalCache(InfinispanSubsystemXMLReader.java:706)
at org.jboss.as.clustering.infinispan.subsystem.InfinispanSubsystemXMLReader.parseContainer(InfinispanSubsystemXMLReader.java:247)
at org.jboss.as.clustering.infinispan.subsystem.InfinispanSubsystemXMLReader.readElement(InfinispanSubsystemXMLReader.java:97)
at org.jboss.as.clustering.infinispan.subsystem.InfinispanSubsystemXMLReader.readElement(InfinispanSubsystemXMLReader.java:70)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69)
at org.jboss.as.server.parsing.StandaloneXml_4.parseServerProfile(StandaloneXml_4.java:547)
at org.jboss.as.server.parsing.StandaloneXml_4.readServerElement(StandaloneXml_4.java:244)
at org.jboss.as.server.parsing.StandaloneXml_4.readElement(StandaloneXml_4.java:143)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:69)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:47)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:123)
... 3 more
How to auto deploy project (customized infinispan manager class(java class), persistence.xml and infinispan-config.xml) in infinispan server(Jboss)?
The two questions are actually related:
Infinispan Server is designed as a backend data store and hence it's not designed to have applications deployed on it.
With that in mind, since you can't deployed applications onto it, you can't deploy JPA entities and hence it does not make sense to be able to configure a JPA cache store in Server mode.
You are able to deploy JPA entities on Wildfly/EAP or similar environments, where it is possible to deploy an Infinispan based application (see tutorials here) and configure a JPA store.
Cheers,
Galder

Setup resources for GlassFish2.x Cargo deployment

I'm trying to get integration testing working for a GlassFish 2.x project, using Maven2 and Cargo. I finally have Cargo attempting to deploy my EAR but it fails to start because the data source is not configured. The app also depends on a few JMS queues and a connection factory - how do I add these?
The Cargo Glassfish 2.x plugin says existing configurations are not supported, so I can't do that.
Using the maven-glassfish-plugin is an option, but we also run OC4J so a Cargo solution would be preferred.
edit: The resources are: 1 JDBC connection pool, 1 JDBC resource, 4 JMS queues, 2 JMS connection factories and a custom security realm (pear tree optional). The realm needs an entry in the login.conf like:
myRealm {
uk.co.mycom.MyGlassFishLoginModule required;
};
I'm not sure (I never used this) but IIRC, you should be able to put your datasource configuration in a sun-resources.xml file and package it under META-INF/sun-resources.xml in your EAR and GlassFish is supposed to create the resources at deploy time.
Here is an example sun-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 9.0 Domain//EN" "sun-resources_1_3.dtd">
<resources>
<jdbc-connection-pool name="SPECjPool" steady-pool-size="100"
max-pool-size="150" max-wait-time-in-millis="60000"
pool-resize-quantity="2" idle-timeout-in-seconds="300"
is-isolation-level-guaranteed="true"
is-connection-validation-required="false"
connection-validation-method="auto-commit"
fail-all-connections="false"
datasource-classname="oracle.jdbc.pool.OracleDataSource">
<property name="URL"
value="jdbc:oracle:thin:#iasperfsol12:1521:specdb"/>
<property name="User" value="spec"/>
<property name="Password" value="spec"/>
<property name="MaxStatements" value="200"/>
<property name="ImplicitCachingEnabled" value="true"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" pool-name="SPECjPool"
jndi-name="jdbc/SPECjDB"/>
</resources>
Give it a try.
Resources
The sun-resources.xml File
Thanks, that worked. The datasource seems to have gone in okay and the app has deployed. However from the doc you linked, I can't see how to add the other things I need (edited more detail into my question about these). This solution also means that I will have to (use profiles to?) build my EAR differently for IT, which is imperfect.
I somehow missed that you wanted to create other resources than Datasources and I've seen several threads reporting that the suggested approach won't work with GlassFish v2 for any resources (like JMS resources). My bad.
So, given the current state, your options are (IMO):
contribute to Cargo to provide an "existing" configuration implementation for GlassFish v2
use the maven-glassfish-plugin as you suggested
I don't have any better suggestions.

JMS Destination creation at deployment with Glassfish 3.0.1

I'm currently trying to 'port' my Java EE 5 Application from Jboss 6 M2 to Glassfish 3.0.1
Jboss used to create my JMS Destination Queues a deployment-time thanks to the -service.xml files. I really liked this feature and I would like to find a way to do the same thing on Glassfish. Is this even possible ?
I'm not sure of the exact status with GlassFish 3.0.1 but according to these threads:
http://markmail.org/thread/cqj56ehulg7qdenp
http://markmail.org/thread/zs4naxy534ijbpic
creating JMS destinations at deploy time was not supported. But these threads are pretty old and things might have changed (see below).
You can however declare them in a sun-resources.xml file and pass it to the asadmin add-resources command.
That being said, several documents (like this one or this one) mention the deployment of application-scoped-resources defined in a sun-resources.xml bundled in the application (that will become glassfish-resources.xml in GlassFish 3.1) as part of the deploy/undeploy of the app but:
I don't know if this is relevant for 3.0.1.
I don't know the exact status, especially for JMS resources.
This would require testing.
With glassfish v4x, Connection factory and destinations(ie queue and topics) can be configured in domain.xml file under glassfish/domains/your-domain-name
Eg :
<resources>
<connector-connection-pool resource-adapter-name="jmsra" max-pool-size="250" steady-pool-size="1" name="jms/DurableConnectionFactory-Connection-Pool" description="connection factory for durable subscriptions" connection-definition-name="javax.jms.ConnectionFactory">
<property name="ClientId" description="MyID" value="MyID"></property>
</connector-connection-pool>
<connector-resource pool-name="jms/DurableConnectionFactory-Connection-Pool" description="connection factory for durable subscriptions" jndi-name="jms/DurableConnectionFactory"></connector-resource>
<admin-object-resource res-adapter="jmsra" description="PhysicalQueue" res-type="javax.jms.Queue" jndi-name="jms/MyQueue">
<property name="Name" value="PhysicalQueue">
</property>
</admin-object-resource>
</resources>

Tomcat 6.x JDBC realm, classpath for driver problem

I've set up a JDBC Realm in my META-INF/Context.xml as shown below, and that works.
The trouble is the JDBC driver now have to be placed under $CATALINA_HOME/lib/
Is there any way I can get that realm to load the jdbc driver from elsewhere, such as WEB-INF/lib/ in my webapp ?
META-INF/Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://daemon/testdb"
userTable="users" userNameCol="userName" userCredCol="password"
connectionPassword="xxxxx"
connectionName="xxxxx"
userRoleTable="users" roleNameCol="role"
digest="MD5"/>
</Context>
I'm pretty sure you can't do that, no. The Realm exists and is managed outside of the scope of any application. Consider the case where two webapps were deployed, for example, with conflicting drivers.
If you need to keep your JDBC driver inside your WAR, then you'll need to do the security management there also, rather than relying on tomcat to do it for you.
I'm not saying I WOULD do this, but I'm sure you could. Check the catalina.sh (or .bat), in there they set up the classpath, if you add the driver JAR in your webapp to the Tomcat classpath then I don't see why you couldn't use the driver in your Realm. I've never tried this, but I don't see why it would not work.
Tried this and it doesnt wrk. Tomcat complains of a ClassNotFound for the referenced jar, even though the refereced jar is present under on on the project's WEB_INF/lib folder.