is Hibernate Elasticsearch compatible with wildfly 14 - java

I am trying to index my entities on AWS Elasticsearch cluster, I am currently using hibernate search and local file for it. Therefore, the hibernate integration with elasticsearch is the only option I have, I've followed the hibernate search doc but it ends up with
Caused by: java.util.ServiceConfigurationError: org.hibernate.search.bridge.spi.IndexManagerTypeSpecificBridgeProvider: Provider org.hibernate.search.elasticsearch.bridge.impl.ElasticsearchBridgeProvider not a subtype
I tried to remove all the jars and clean install maven once again, it didn't change anything
I've tried to add the hibernate-search-elasticsearch as a module in wildfly but ends up with many issues as well like Lucene query parser is not found in the class loader (maybe I missed up something while adding the jar as a module )
As I understood I don't need server provisioning since I am using the version which is supported by wildfly (correct me if I am wrong).
I am using:
Wildfly server 14.0.1
Hibernate core 5.3.6.Final
Hibernate search orm 5.10.3.Final
Hibernate search elasticsearch 5.10.3.Final
any ideas what could be wrong? and the better question am I adding the correct dependencies for wildfly?
P.S I know the similar question was asked before but the answer didn't help at all.

All that needed to be done is to add the dependency for hibernate elasticsearch as compile scope and add those properties in persistence.xml.
<property name="jboss.as.jpa.providerModule" value="org.hibernate" />
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm" />

Related

Hibernate 5 + Glassfish 4.1.1: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V

When I add Hibernate 5 to my website, I can't get it to work in Glassfish 4.1.1. I always get an error
java.lang.NoSuchMethodError:
org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
I've tried to replace the jboss-logging library in Glassfish' modules folder, like I read in an answer to a similar problem, but it didn't change anything. I also tried to use Hibernate 4, but that gave an other error.
In my case, I was running the Hibernate 5 with JPA annotations on tomcat and stop working when I changed to glassfish 4.1
The error:
hibernate.properties not found
Make sure: src/main/resources/hibernate.cfg.xml exists
And if you only have the dependency of hibernate-core, I was using hibernate-annotations and hibernate-common-annotations and it was creating conflict. The hibernate 5 doesnt need these two, I had read somewhere.Try to remove ;)
After that a new error appears:
java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
The reason was the oldest jboss-logging.jar at:
"YOUR_GLASSFISH_FOLDER/glassfish/modules"
Why? The hibernate 5 has dependency with the newest version of
jboss-logging, and the glassfish 4 uses the oldest version even if you
declare inside your POM file the newest version. Actually I'm using:
org.jboss.logging jboss-logging 3.3.0.Final
Then I downloaded it and replace the old .jar inside the modules path
and it back to work, I spent 2 days trying to solve that and I hope it
helps some future issues =D
I used this link to help me: https://medium.com/#mertcal/using-hibernate-5-on-payara-cc242212a5d6#.npq2hdprz
Another solution, in my case, could be back to the last Hibernate 4 version (4.3.11.Final) but it is already too old in my opinion
I had a similar issue, I was able to fix it by creating a glassfish-web.xml file in the WEB-INF directory. The contents of the file are shown below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
 <class-loader delegate="false"/>
</glassfish-web-app>
This ensures that glassfish does not load it's internal libraries, but libraries from your project..
Try to clean glassfish osgi-cache folder in your domain. You can find details in this Payara github issue: https://github.com/payara/Payara/issues/554 (Payara is a fork of Glassfish with additional features, so basic mechanics remain the same as in Glassfish)

NoSuchMethodError: org.hibernate.SessionFactory.openSession()

I'm having hibernate3.jar and hibernate-core-4.2.0.CR1.jar in my classpath and I'm using Spring 3.1.3 version. Code got compiles sucessfully but while runtime I'm getting following error
2014-10-28 10:51:25,174 DEBUG [RMI TCP Connection(2)-10.126.30.203] -
Target method failed for RemoteInvocation: method name
'getPriceByKeys'; parameter types [java.util.List, java.util.Date]
java.lang.NoSuchMethodError:
org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
I google it but not find any solution. Please note : My project needs hibernate3.jar but at the same time my project dependent on some other 3rd party jar which inturn using hibernet4.2.0 jar.
Any help Pls ??
You need to remove multiple hibernate JAR files from your classpath. Without doing this, your application may not work as you expect; which means you need to migrate the hibernate version of your application from 3 to 4.1.
Although Spring 3.1 uses Hibernate 3 JAR files, you can still migrate to Hibernate 4. Check out Spring blog gives a small tutorial to do so.
Migrating to Spring 3.1 and Hibernate 4.1
As part of the Core-Spring course, we have a lab application that we
use to show how to integrate Spring and JPA/Hibernate together. We
have just upgraded it to Spring 3.1 / Hibernate 4.1, and thought we
should share a few tips.
Just an update. The cause of problem is , I'm having two spring-context xml files in project (one of my project and one related to another module that I'm integrating). I'm loading context xmls from two different classes. So one of the DAO class loaded by one of spring-context xml not getting the hibernate Session.
Later on using import tag, I included 2nd spring application context file in 1st application context file and then loaded a Single application context file from the class. It solved the error.
Thanks,

javax.mail.Session in cloudBees

I am developing a webapp in cloudbees platform and trying to add functionality for sending mail.
I am following https://wiki.cloudbees.com/bin/view/RUN/SendGrid documentation and as per the document we can get the mail session using below:
Context initCtx = new InitialContext();
Session session = (Session) initCtx.lookup("java:comp/env/mail/SendGrid");
But when running thie code in cloud i am getting:
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session.
the problem seems to be with javax.mail.jar
i have downloaded the latest jar from https://java.net/projects/javamail/pages/Home .
As i understand the version which is required in cloud bees is different from what i am deploying.Can anyone help in getting correct jar for this particular purpose.
Note: I have added send grid to my stack in cloudBees.
I think you have more than one version of the javax.mail.
Indeed, the java mail session jars should be already provided by the container.
You can refer to this, as example: https://github.com/CloudBees-community/tomcat7-sendgrid-clickstart/blob/master/pom.xml
Try to remove your mail jar and if it still does not work and you are using maven try using the dependency plugin with
mvn dependency:tree -Dverbose
to check if you have conflicts with mails dependencies.
Duplicate Problem Resolved with Spring Framework on Cloudbees
I had the same problem only from Spring and can confirm it was from including javax-mail in the Maven dependencies (which also brings in the mail jar). After taking out the dependency/jar file I was having a problem with the constructor for org.springframework.mail.javamail.JavaMailSenderImpl not liking the type of the argument from jndi, however. At least the original error seemed to be objecting to the same class rather than saying it didn't know the type/name/etc. Finally, taking out passing the session to the constructor and putting it in the property (which in theory should do the same thing, I believe) fixed the problem:
<jee:jndi-lookup id="mailSource"
jndi-name="java:comp/env/mail/SendGrid"
expected-type="javax.mail.Session" />
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="mailSource" />
</bean>

Does Hibernate 4 with ehcache require ehcache-core library?

I am attempting to upgrade an appliaction from Hibernate 3 to Hibernate 4. The application uses ehcache.
When upgrading to Hibernate 4.2.0.Final I added a dependency on hibernate-ehcache-4.2.0.Final as suggested.
When I started up the application I received the following error:
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion
According to http://www.javacraft.org/2012/03/migrate-to-hibernate-4-ehcache.html I should remove the dependency on ehcache-core and only use the hibernate provided jar to resolve this error.
Now, if I follow these instructions and remove this dependency my application which uses the net.sf.ehcache.CacheManager no-longer compiles.
// For example, this no-longer works
CacheManager manager = CacheManager.getInstance();
So my question is, can I use both libraries and continue working as before (Without updating the app), or do I have to change the app, in which case does hibernate-ehcache even provide the functionality required to access the cache?
When using Hibernate 4 you have to use the org.hibernate packaged classes.
The net.sf.ehcache ones are target at Hibernate 3.
Form 4 they have ported to 4 within the Hibernate repo directly (which is the most sensible thing in our opinion).
So using org.hibernate.cache.ehcache.EhCacheRegionFactory should solve your problem.
Check if there any .properties file in your project like hsqlDatabaseConfig.properties, try to update the property as below
sessionFactory.hibernateProperties = hibernate.cache.use_second_level_cache=true\n\
hibernate.cache.use_query_cache=true\n\
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.internal.EhcacheRegionFactory\n\

GWT with JPA - no persistence provider

GWT with JPA
There are two projects in my eclipse workspace, let's name them:
-JPAProject
-GWTProject
JPAProject contains JPA configuration stuff (persistence.xml, entity classes and so on). GWTProject is an examplary GWT project (taken from official GWT tutorial).
Both projects work fine alone. That is, I can create EMF (EntityManagerFactory) in JPAProject and get entities from the database. GWTProject works fine too, I can run it, fill the field text in the browser and get the response.
My goal is to call JPAProject from GWTProject to get entities. But the problem is that when calling DAO, I get the following exception:
[WARN] Server class 'com.emergit.service.dao.profile.ProfileDaoService' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/home/maliniak/workspace/emergit/build/classes/' to the web app classpath for this session
[WARN] /gwttest/greet
javax.persistence.PersistenceException: No Persistence provider for EntityManager named emergitPU
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.emergit.service.dao.profile.JpaProfileDaoService.<init>(JpaProfileDaoService.java:19)
at pl.maliniak.server.GreetingServiceImpl.<init>(GreetingServiceImpl.java:21)
...
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
[ERROR] 500 - POST /gwttest/greet (127.0.0.1) 3812 bytes
I guess that the warnings at the beginning can be omitted for now.
Do you have any ideas? I guess I am missing some basic point. All hints are highly appreciated.
Update: My persistence provider is well defined, the JPA project works well by itself.
I guess it's classpath related problem too. When running the GWT project, in WEB-INF/lib there is only gwt-servlet.jar.
Do you think that making custom Ant file to build whole thing up is the only solution (i.e. make jar out of the JPA project and copying it to WEB-INF/lib)? Or is there any Eclipse solution, so I could set the GWT project properties properly so GWT project would know to include persistence.xml file?
Update: OK, I got it working. I tried to put persitence.xml everywhere in war/WEB-INF where it was possible, but kept getting 'no persistence provider' error. It turned out that it wasn't about persistence.xml. I didn't copy the eclipselink jar to WEB-INF/lib, so it couldn't find provider class defined in persistence.xml. Copying all the jars did the thing.
Thank you very much Pascal.
Struggling a lot with the same error message, I solved the problem with copying all jars (eclipselink.jar, eclipselink-jpa-modelgen_2.1.0.v20100614-r7608.jar, javax.persistence_1.0.0.jar, javax.persistence_2.0.1.v201006031150.jar) from the EclipseLink zip to the .../war/WEB-INF/lib folder of my GWT project to make everything available for the Jetty in hosted mode.
As you can see from the list of files, I was using EclipseLink 2.1. Please adapt this list to your JPA implementation, if necessary.
Hoping, that this may help you as well.
Do you have a persistence provider declared in your persistence.xml? Something like this (I'm using Hibernate here, adapt it to whatever persistence provider you're using):
<persistence
<persistence-unit name="emergitPU" transaction-type="...">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
</persistence-unit>
</persistence>
If you do, then I suspect a classpath problem. Did you package the JPA project correctly in the webapp i.e. in WEB-INF/lib?

Categories