javax.persistence.PersistenceException : [PersistenceUnit: vodPersistenceUnit] class or package not found - java

I got the following error :
Error creating bean with name
'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
defined in class path resource [jpaDaoContext.xml]: Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'vodEntityManagerFactory' defined in class
path resource [jpaDaoContext.xml]: Invocation of init method failed;
nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: vodPersistenceUnit] class or package not found
I had a look on Google and I was told to choose transaction-type=RESOURCE_LOCAL but the settings were already that way. What is wrong with these settings :
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<!-- transaction-type is RESOURCE_LOCAL or JTA -->
<persistence-unit name="vodPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<class>mypackage.persistent.HistoriqueAction</class>
<class>mypackage.persistent.ParametresTechniques</class>
<class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class>
<class>mypackage.persistent.Statistique</class>
<class>mypackage.persistent.StatUser</class>
<!-- Avoid to scan *.class and *.hbm.xml -->
<exclude-unlisted-classes />
</persistence-unit>
</persistence>
Regards

I fixed the issue. I had to comment these three lines in the file "persistence.xml" :
<!--class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class-->
For the moment i have no idea why it fixes the issue. It is really hard to debug this spring file.

If you had to comment out the "class" elements, it is likely that one of those classes is either not defined, or is not available in the classpath.
I faced the same exact error, and it was resolved once the fully qualified names were all correct. Ideally, Hibernate should tell you what class is not found, but sadly it does not do it in this case.

You you haven't done that, put <property name="persistenceUnitName" value="vodPersistenceUnit" /> in your jpaDaoContext.xml as property of your entityManagerFactory bean definition like:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="vodPersistenceUnit" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">...</property>
</bean>

I was running into this exception when trying to run a Spring Boot application in WebLogic 12.1.3 In the dependency tree I found out spring-tx was being included from one of the common project libraries. Our particular app only calls web service so there is no need for database access. So in the library dependency I added:
<exclusions><exclusion> <groupId>org.springframework</groupId><artifactId>spring-tx</artifactId></exclusion></exclusions>

Related

Migrating Grails (2.2.4) application from JBoss 5.1 to Wildfly 8.2.1

I am new to grails and trying to migrate a Grails (2.2.4) application (on jdk 1.6) from JBOSS 5.1 to Wildfly 8.2.1 server.
As wildfly takes default class-loader,I commented out class-loading tag in jboss-web.xml. After this, I did following steps.
run command: grails test war.
deploy on wildfly 8.2.1
The deployment failed with error:
ERROR [StackTrace] (MSC service thread 1-5) Full Stack Trace:: org.springframework.beans.factory.BeanCreationException: **Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: ** Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method getAt() on null object
ApplicationContext.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
<description>Grails application factory bean</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="grailsResourceLoader" ref="grailsResourceLoader" />
</bean>
<bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
<description>A bean that manages Grails plugins</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="application" ref="grailsApplication" />
</bean>
<bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
<constructor-arg>
<ref bean="grailsApplication" />
</constructor-arg>
<property name="pluginManager" ref="pluginManager" />
</bean>
<bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />
<bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
<property name="encoding">
<value>utf-8</value>
</property>
</bean>
</beans>
As per suggestions given in other posts, I tried to deploy after removing "grailsResourceLoader" bean (as it is deprecated) and its ref, but still same issue occurs.
I used jdk 1.6 as well as 1.7 for appplication, but of no use.
Any other files that need to be changed for configurations to run on wildfly 8.2.1 ?
any ides what can be the issue?
Thanks.
Able to deploy the war by changing jdk version to 1.7 for project as well as for wildfly 8.2.1

ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource

I was trying to do some basic database operations. I'm using STS 3.2.0, Apache Tomcat 7.
My dispatcher-servlet.xml includes:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mydb" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
Apache Tomcat fails miserably with thousands of exceptions, starting with this one :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
EDIT 1: I also downloaded 3.0.3.RELEASE version of the jar, and its still the same.
FINAL EDIT It seems, you should add your external jar files manually to your deployment directory as well (well if you don't use any extension that'd do that for you)
Try to add to POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
I think you should import selected jdbc jar into web app library.
if none of the above solution doesn't work, then manually add spring-jdbc jar file to webapp/WEB-INF/lib.

Spring 3.1.1 and Cache configuration issue

I'm testing the Spring cache and, this is my context file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven cache-manager="simpleCacheManager"/>
<bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco"/>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco_article"/>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco_action"/>
</bean>
</set>
</property>
</bean>
I added all required library but, I cannot validate the library because Eclipse still tells me that AOPAlliance.jar and org.springframework.context-3.1.1.RELEASE.jar are missing.
The error is:
Multiple annotations founds at this line: class org.springframework.cache.concurrent.ConcurrentCacheFactoryBean not found.
SOLVED changing to org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean
but, calling the url this happens:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
aop-alliance.jar and org.springframework.aop-3.1.1.RELEASE.jar are both in classpath.
Any clue?
Thanks,
Andrea
Double-check that org.springframework.context-3.1.1.RELEASE.jar is indeed on the classpath. Both Eclipse validation and the error point at this issue.
UPDATE: I've checked, and you are right. ConcurrentCacheFactoryBean seems to be removed since 3.1.0.M1 and is possibly replaced by ConcurrentMapCacheFactoryBean in the same package. I wasn't able to find any proof in the release notes yet. However, if you change the bean class name for your caches to ConcurrentMapCacheFactoryBean, it does seem to work fine.
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="alfresco"/>
</bean>
UPDATE2: Yes, indeed ConcurrentCacheFactoryBean has been renamed to ConcurrentMapCacheFactoryBean. They just didn't get around to update the tutorial.

How can i defind <non-jta-data-source> </non-jta-data-source> in persistence.xml?

How can i define <non-jta-data-source> </non-jta-data-source> in persistence.xml?
My project runs well in Tomcat 6 and Tomcat 7.
now i am using
Struts 2
Spring 3.0.5
JPA 2
Jboss 6
my persistence.xml looks likes this
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="axw-db" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
**<non-jta-data-source></non-jta-data-source>**
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/abc"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.ejb.autodetection" value="class"/>
</properties>
</persistence-unit>
</persistence>
now i am getting this exception
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/icc-web-struts2-1.0.0-SNAPSHOT]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in URL [vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-core.jar/core-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-core.jar/core-config.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan : vfs:/D:/workspace/icc-temp/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1319268021951/deploy/icc-web-struts2.war/WEB-INF/lib/icc-domain.jar/
The non-jta-data-source is used to define a datasource which doesn't use the existing JTA manager. If you're interested exactly in this feature, than it accepts the JNDI location of the non-JTA data source (i.e. java:app/jdbc/yourNonJTAsource).
The Datasource should be configured in your application server and this configuration is vendor-specific. Try accessing the JBoss web admin console and create/define the Pool/Datasource there. If that's the case, than you can get rid of those user/password/url/... stuff from your persistence.xml as these information will be moved to the Application Server.
If you're using this persistence.xml totally outside of the container, than you probably don't need the non-jta nor the jta datasources, as you cannot rely on the JNDI outside the container.
HTH.

Spring 3.0 lazy-init not honoured for DefaultMessageListenerContainer?

I've setup a spring config for JMS. Things work fine, except I can't seem to get it to lazy load (notice the default-lazy-init true in the code below). If I comment out the jmsContainer(DMLC) from my config below, lazy loading works as expected. Otherwise, it will instantiate the DMLC, which in turn creates the queue and connection factory.
What am I missing?
jmsContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="true">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3:localhost:7001</prop>
</props>
</property>
</bean>
<bean id="queue" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiTemplate-ref="jndiTemplate" p:jndiName="jms/queue"/>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiTemplate-ref="jndiTemplate" p:jndiName="jms/connectionfactory"/>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver"
p:jndiTemplate-ref="jndiTemplate" p:cache="true" />
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
p:autoStartup="false"
p:destination-ref="queue"
p:destinationResolver-ref="jmsDestinationResolver"
p:connectionFactory-ref="connectionFactory"
p:messageListener-ref="queueListener" />
<bean id="queueListener" class="com.blah.QueueListener"/>
</beans>
And the test I'm using to drive it, DummyTest.java:
package blah;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("classpath:jmsContext.xml")
public class DummyTest {
#Test
public void shouldDoSomething() {
}
}
When jmsContainer is commented out, the test above passes. Otherwise, I get this:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jmsContainer' defined in class path resource [com/blah/config/jmsContext.xml]:
Cannot resolve reference to bean 'connectionFactory' while setting bean property 'connectionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'connectionFactory' defined in class path resource [com/blah/config/jmsContext.xml]:
Invocation of init method failed; nested exception is javax.naming.NameNotFoundException:
Exception in lookup.: `jms/connectionfactory' could not be found.
[Root exception is weblogic.corba.cos.naming.NamingContextAnyPackage.NotFound: IDL:weblogic/corba/cos/naming/NamingContextAny/NotFound:1.0]
The "connectionFactory" bean gets instantiated as a dependency of "jmsContainer" and it fails. With "jmsContainer" commented out, "connectionFactory" does not get instantiated.
The jms code works fine, but I have renamed my JNDI names on purpose so I can see when things get started.
OK, this is pretty obscure, but DefaultMessageListenerContainer implements the Lifecycle interface, and beans that implement this are tied into the context's own lifecycle - when the context starts up, Lifecycle-implementing beans are initialised and started. This means that your lazy-init config is essentially ignored.
The solution is to use autoStartup to false. See the code below.
<bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
........
<property name="autoStartup" value="false"/>
</bean>
~Shyam

Categories