Im currently working on a JPA Jersey Servlet and Im trying to use Guice for dependency injection. The Problem is, that I get the following error:
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.google.inject.CreationException: Guice creation errors:
1) null returned by binding at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:63)
but parameter 1 of com.google.inject.persist.jpa.JpaPersistService.<init>() is not #Nullable
while locating java.util.Properties annotated with #com.google.inject.persist.jpa.Jpa()
for parameter 1 at com.google.inject.persist.jpa.JpaPersistService.<init>(JpaPersistService.java:43)
at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:67)
while locating com.google.inject.persist.jpa.JpaPersistService
for field at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.emProvider(JpaLocalTxnInterceptor.java:33)
at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:76)
2) null returned by binding at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:63)
but parameter 1 of com.google.inject.persist.jpa.JpaPersistService.<init>() is not #Nullable
while locating java.util.Properties annotated with #com.google.inject.persist.jpa.Jpa()
for parameter 1 at com.google.inject.persist.jpa.JpaPersistService.<init>(JpaPersistService.java:43)
at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:67)
while locating com.google.inject.persist.jpa.JpaPersistService
while locating com.google.inject.persist.UnitOfWork
for field at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.unitOfWork(JpaLocalTxnInterceptor.java:36)
at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:76)
2 errors
The code that i generating this error is:
install(new JpaPersistModule("theseen"));
filter("/*").through(PersistFilter.class);
If I use the "standard" way by instantiating a EntitiManager and uncommenting these lines, nothing happens.
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("theseen");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.merge(s);
em.getTransaction().commit();
works like a charm. So I think the setup if the database connection must be ok.
What could these to errors possibly be? I tested the same App on another test environment and it works! Both machines use Glassfish 3.1, Eclipse Indigo with m2eclipse and m2wtp integration. I use Guice 3.0 with guice-persist 3.0 and guice-servlet 3.0. The machine where the app is working runs Ubuntu 11.04 with OpenJDK, the machine where problems occure uses Windows 7 with JDK1.6v26. I normally use a Datasource provided by Glassfish, but even using a plain persistence.xml is not working.
I am seriously confused...
Any ideas what is wrong with Guice Injection for JPA?
Since nobody answered I went brute force:
Completely reinstall Glassfish and the WebApp worked...
Something must have been corrupted during the long months of testing here on my local machine.
Related
We have a Spring-Boot application exposing some REST endpoints. We allow for this application to be operated standalone (as executable jar) or as a war to be deployed in a wildfly-11 application-server.
The class defining the REST-endpoints is marked #RestController #Transactional(REQUIRES_NEW) (both on class level, obviously). When running standalone, everything works as expected but when deployed in wildfly, the rollback on exceptions does not work. We established this by sending the exact same REST-message while operating on the exact same database.
We have confirmed via debugging that the final frames of the stacktrace is identical in both cases and especially in both cases we see a transactional-proxy around our REST-controller bean.
One difference would be, that within wildfly the application will use a jndi-datasource, prepared by wildfly while standalone the spring-boot will manage the database-connections.
Any idea what is wrong here?
Edit
I just tried explicitly invoking setRollbackOnly on the JtaTransactionmanager from within my code. The transaction will still commit. This sort of looks like a bug in Spring Boot to me.
Edit 2
Debugging further reveals that the transaction seems to be set to autocommit - every statement is immediately written to the database. This seems to be in violation to the annotation #Transactional and also to the fact that Spring creates a transactional proxy around my bean.
It's not a full answer - just a reasoning. JNDI is usally used at the app server layer whereas JDBC - at the application layer. At the App server layer are used global transaction settins that are overriding app settings. Follow the spring doc to get more
For reasons beyond my understanding the default transactional behaviour when deploying a spring-boot webapp to an application-server is auto-commit.
The solution to this problem is to enrich your application-configuration with the property spring.datasource.tomcat.default-auto-commit=false
when I try to deploy my application on Websphere Application Server 9.0 I got this error
An error occurred in the org.hibernate.jpa.HibernatePersistenceProvider persistence provider when it attempted to create the container entity manager factory for the ApplicationEntityManager persistence unit. The following error occurred: java.lang.ClassCastException: org.hibernate.jpa.HibernatePersistenceProvider incompatible with javax.persistence.spi.PersistenceProvider
and someone suggests me to downgrade my JPA to 2.0. is this possible to use JPA 2.0 with Hibernate 5.2.1. or there is another solution to solve my problem.
If using WebSphere Application Server traditional,
here are the instructions to set the JPA spec level provided by the server,
https://www.ibm.com/support/knowledgecenter/en/SSEQTP_9.0.0/com.ibm.websphere.base.doc/ae/tejb_idmod_jpaspec.html
That said, Hibernate 5.2.1 appears to have a dependency on JPA 2.1, not 2.0. See the dependencies indicated here,
https://mvnrepository.com/artifact/org.hibernate/hibernate-core/5.2.1.Final
The issue might be caused by including a copy of the JPA spec JARs within the application such that the server and the application are trying to load different copies of the same class which collide and produce this error. Check your application and remove all copies of the JPA spec JAR from it (including any supplied by Hibernate), such that the server copy alone is always used to load JPA.
Using Spring within Websphere, when using the javax.transaction.Transactional. Running the code locally or within Tomcat works as intended but while running within Websphere, it appears that the javax.transaction.Transactional annotation is not resulting in a Transaction that includes the JPA-EntityManager. Replacing the javax.transaction.Transactional annotation with the Spring version of Transactional solves this issue.
We would like to know what is required to fix this issue. I found this Stackoverflow-issue: spring-jta-transaction-with-jpa-and-jndi-datasource-for-websphere which links to the Article: 0609_alcott-pdf.pdf
The advise given is to configure Spring to use the WebSphereUowTransactionManager as transaction manager.
The stackoverflow answer is from 2012. But since we are running a farely old WebSphere 7 version, it might sill be relevant to us.
Does anyone experienced the similar or a related problem?
Update
The following dependencies are used:
spring-core: 4.3.9
hibernate.core: 4.2.15.Final
spring-boot starter: 1.5.4.RELEASE
I'm getting the following exception when starting a Tomcat instance with my web app after upgrading to Hibernate 3.5.0:
org.hibernate.annotations.common.AssertionFailure: Fail to process type argument in a generic declaration. Type: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.getClassFromGenericArgument(AttributeFactory.java:836)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.getClassFromGenericArgument(AttributeFactory.java:833)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:748)
at org.hibernate.ejb.metamodel.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:723)
at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:518)
at org.hibernate.ejb.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:93)
As this happens on Tomcat startup, I have no idea where to look in my code to prevent that :-(
Putting that error message into google would have shown you any number of explanations, including this JIRA issue:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5098
I have an app using Wicket for the presentation layer with CDI/Weld, JPA 2.0, EJB 3.1 etc. (Java EE 6) deployed on GlassFish v3.0.1.
When I try to inject an EJB into a wicket page using #EJB I get the following error:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName
When I try to inject using #Inject, I get the following error:
java.lang.IllegalStateException: Unable to convert ejbRef for ejb UserRepository to a business object of type class
I believe the problem is stemming from JPA. I am using the exact same configuration that I used with a JSF application which worked properly, so I am lost as to what the issue could be. The connection pools are set up properly and pinging correctly through GlassFish, I have included wicket-weld on the classpath and I have even tried using the old Java EE 5 wicketstuff project for wicketstuff-javaeeapi with the same results.
Any help would be appreciated.
If you get the exception:
Unable to retrieve EntityManagerFactory for unitName
It might mean it is not detecting your persistence.xml file. Make sure it's in the WEB-INF\classes\META-INF directory.
You can verify that your app has JPA enabled by going to the Admin Console in GlassFish, go to the Applications section and see if it shows something like [ejb, web, weld, jpa] for your app. If it doesn't show jpa then it's not finding your JPA config file.
Could always try to lookup the EJB via its standard "java:global" name. That should at least let you rule out wicket as a possible source of issues and get you a little closer to a working system.