Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean 'org.spring....PersistenceExceptionTranslationPost Processor#0' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean 'org.spring....PersistenceExceptionTranslationPost Processor#0'

    Hi all,

    The following error appears when I try to enter at my main url application localhost:8080/springmvc/, with VMware vFabric tc server 2.8.2 previously executed, using STS last version:

    These are a chain of concatenated errors:


    note: my Spring xml context configuratior is servlet-context.xml


    HTTP 500 state, exception at Servlet.init()

    Root cause:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0' defined in servlet-context.xml

    ": Error creating bean with name 'sessionFactory' defined in servlet-context.xml

    org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean]: Constructor threw exception

    java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration
    org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean.<init>

    There is something I should know about defining a PersistenceExceptionTranslationPostPorcessor in my xml Spring file? Or maybe error begins with defining the AnnotationSessionFactoryBean bean?

    Here are the servlet-context.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/mvc"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    
    	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    	
    	<!-- Enables the Spring MVC @Controller programming model -->
    	<annotation-driven />
    
    	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    	<resources mapping="/resources/**" location="/resources/" />
    
    	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<beans:property name="prefix" value="/WEB-INF/views/" />
    		<beans:property name="suffix" value=".jsp" />
    	</beans:bean>
    	
    	<context:component-scan base-package="cat.tfcproject.springmvc.persistence
    										  cat.tfcproject.springmvc" />
    	
            <!-- Here begin the HIBERNATE - SESSION FACTORY BEAN - TRANSLATOR PROCESSOR - TRANSACTION MANAGER configuration -->
    	<jee:jndi-lookup id="dataSource"
    		jndi-name="/hibernate/TFCappDS"
    		resource-ref="true"/>
    		
    	<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<beans:property	name="dataSource" ref="dataSource"/>
    		<beans:property name="packagesToScan" value="cat.tfcproject.springmvc.domain"/>
    		<beans:property	name="hibernateProperties">
    			<beans:props>
    				<beans:prop	key="dialect">org.hibernate.dialect.HSQLDialect</beans:prop>
    			</beans:props>
    		</beans:property>
    	</beans:bean>
    	
    	<beans:bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    	
    	<!-- Configuració xml per a la gestió de transaccions -->
    	
    	<beans:bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<beans:property name="sessionFactory" ref="sessionFactory"/> 
    	</beans:bean>
    	
    	<tx:annotation-driven transaction-manager="txManager"/>
    	
    </beans:beans>

    I'm sure that errors are between <jee:jndi-lookup> and <tx:annotation-driven> elements

    ( POST CONTINUE IN THE FIRST THREAD REPLY with the rest of code files)

  • #2
    Only if necessary, here is pom.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>cat.tfcproject</groupId>
    	<artifactId>springmvc</artifactId>
    	<name>TFCapp</name>
    	<packaging>war</packaging>
    	<version>1.0.0-BUILD-SNAPSHOT</version>
    	<properties>
    		<java-version>1.6</java-version>
    		<org.springframework-version>3.2.3.RELEASE</org.springframework-version>
    		<org.aspectj-version>1.6.10</org.aspectj-version>
    		<org.slf4j-version>1.6.6</org.slf4j-version>
    		<javax-transaction-version>1.1</javax-transaction-version>
    	</properties>
    	<dependencies>
    		<!-- Spring -->
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>${org.springframework-version}</version>
    			<exclusions>
    				<!-- Exclude Commons Logging in favor of SLF4j -->
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				 </exclusion>
    			</exclusions>
    		</dependency>
    		
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-orm</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-webmvc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    			
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-core</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    				
    		<!-- AspectJ -->
    		<dependency>
    			<groupId>org.aspectj</groupId>
    			<artifactId>aspectjrt</artifactId>
    			<version>${org.aspectj-version}</version>
    		</dependency>	
    		
    		<!-- Logging -->
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>${org.slf4j-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>jcl-over-slf4j</artifactId>
    			<version>${org.slf4j-version}</version>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-log4j12</artifactId>
    			<version>${org.slf4j-version}</version>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>log4j</groupId>
    			<artifactId>log4j</artifactId>
    			<version>1.2.15</version>
    			<exclusions>
    				<exclusion>
    					<groupId>javax.mail</groupId>
    					<artifactId>mail</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>javax.jms</groupId>
    					<artifactId>jms</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>com.sun.jdmk</groupId>
    					<artifactId>jmxtools</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>com.sun.jmx</groupId>
    					<artifactId>jmxri</artifactId>
    				</exclusion>
    			</exclusions>
    			<scope>runtime</scope>
    		</dependency>
    
    		<!-- @Inject -->
    		<dependency>
    			<groupId>javax.inject</groupId>
    			<artifactId>javax.inject</artifactId>
    			<version>1</version>
    		</dependency>
    				
    		<!-- Servlet -->
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>servlet-api</artifactId>
    			<version>2.5</version>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet.jsp</groupId>
    			<artifactId>jsp-api</artifactId>
    			<version>2.1</version>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>jstl</artifactId>
    			<version>1.2</version>
    		</dependency>
    	
    		<!-- Test -->
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.7</version>
    			<scope>test</scope>
    		</dependency>
    		
    		<!-- Java Standard Tag Library -->
    		<dependency>
    			<groupId>jstl</groupId>
    			<artifactId>jstl</artifactId>
    			<version>1.2</version>
    		</dependency>
    		
    		<!-- Hibernate dependences  -->
    		<dependency>
            	<groupId>org.springframework</groupId>
            	<artifactId>spring-hibernate3</artifactId>
           		<version>2.0.8</version>
          	</dependency>
          	
          	<dependency>
    			<groupId>javax.transaction</groupId>
    			<artifactId>jta</artifactId>
    			<version>1.1</version>
    		</dependency>
    		
    	</dependencies>
    	
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <additionalProjectnatures>
                            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        </additionalProjectnatures>
                        <additionalBuildcommands>
                            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                        </additionalBuildcommands>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArgument>-Xlint:all</compilerArgument>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2.1</version>
                    <configuration>
                        <mainClass>org.test.int1.Main</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    and finally my DAO interface and implementation, only if necessary:

    Dao Interface
    Code:
    package cat.tfcproject.springmvc.persistence;
    
    import cat.tfcproject.springmvc.domain.Client;
    import cat.tfcproject.springmvc.domain.Proveidor;
    
    public interface TFCappDAO {
    	void addClient(Client client);
            ...
            ...
    }
    Dao implementation
    Code:
    package cat.tfcproject.springmvc.persistence;
    
    import org.hibernate.SessionFactory;
    import org.hibernate.classic.Session;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;
    
    import cat.tfcproject.springmvc.domain.Client;
    import cat.tfcproject.springmvc.domain.Proveidor;
    
    @Repository
    public class HibernateTFCappDAO implements TFCappDAO{
    	private SessionFactory sessionFactory;
    	
    	@Autowired
    	public HibernateTFCappDAO(SessionFactory sessionFactory){
    		this.sessionFactory = sessionFactory;
    	}
    	  
    	private Session currentSession(){
    	    return sessionFactory.getCurrentSession();
    	}
    	  
    	public void addClient(Client client){
    		currentSession().save(client);
    	}
            ...
    }
    and Client.java data access object:
    Code:
    package cat.tfcproject.springmvc.domain;
    
    import org.springframework.beans.factory.annotation.Configurable;
    import cat.tfcproject.springmvc.persistence.TFCappDAO;
    
    @Configurable("client")
    public class Client {
    	// injected
    	private TFCappDAO _tfcappDAO;
    	
    	private Long _id;
    	private String _username;
    	private String _password;
    	
    	public void save() {
    		_tfcappDAO.saveClient(this);
    	}
    	...
    }
    I'm sure all group dependency versions at pom.xml are updated, and I'm really lost founding a solution.

    Can someone help me?

    Comment


    • #3
      Your application is unable to find the "org/hibernate/cfg/AnnotationConfiguration" class. This mean, hibernate library is missing in your web server lib folder.
      java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration
      Please add hibernate libraries in Web Server lib folder and try again.

      Comment


      • #4
        So, If I understood, adding hibernate libraries as a maven dependency in pom.xml is not enough, I have to add hibernate jars into Server lib folder. But, where this folder is? I have to creare a new 'lib' folder, inside WEB-INF folder? Pd: sorry for the image, is a mistake
        Last edited by bonetky; Jun 18th, 2013, 07:04 AM.

        Comment


        • #5
          What you have added in your pom.xml file is org.springframework.spring-hibernate3 jars.
          <!-- Hibernate dependences -->
          <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-hibernate3</artifactId>
          <version>2.0.8</version>
          But what is required is "org.hibernate"
          <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>[Your Hibernate version]</version>
          <type>jar</type>
          </dependency>
          Try with changing the pom.xml file with correct hibernate jars.

          Comment


          • #6
            Thnaks very much

            Effectively the error has gone adding the org.hibernate groupId dependency.

            But now, I have a new error executing application into the client browser:

            javax.naming.NameNotFoundException: name hibernate/TFCappDS is not associated at this context
            I know where the root cause is, but I really have no idea about what name should it really have

            This is my JNDI-lookup bean definition, in Spring xml configuration file:

            Code:
            <jee:jndi-lookup id="dataSource"
            		jndi-name="/hibernate/TFCappDS"
            		resource-ref="true"/>
            And this is the sessionFactory bean associated with the jndi bean:
            Code:
            <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            		<beans:property	name="dataSource" ref="dataSource"/>
            		<beans:property name="packagesToScan" value="cat.tfcproject.springmvc.domain"/>
            		<beans:property	name="hibernateProperties">
            			<beans:props>
            				<beans:prop	key="dialect">org.hibernate.dialect.HSQLDialect</beans:prop>
            			</beans:props>
            		</beans:property>
            	</beans:bean>
            I actually invented that '/hibernate/TFCappDS' name.
            To associate this name with the context, what should I do? Or otherwise, should I put an specific name? How can I know what specific name I must write?

            Very thankful for your help

            Comment


            • #7
              All these JNDI names are exposed by Application Servers. If you connect to you Application Server's JMX console, you will see all the services that are exposed by the Application Services. From there you pick up the correct JNDI name for dataSource.

              e.g.: To do look up for dataSource from JBoss Application Server
              <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/sampleDS"/>

              Comment


              • #8
                Ok, the problem is I have no idea how to connect to my Application Srever's JMX console. After an exhaustive search I found something about JNDI look-up name has to be defined as a <resource> into Server.xml from my VMware vFabric tc Server, something like this:

                inside server.xml file server, something like this, but with proper values using Hibernate
                Code:
                <GlobalNamingResources>
                     <Resource name="DBNAME" auth="Container" type="javax.sql.DataSource"
                              username="dbUsername" password="dbPasswd"
                              url="jdbc:postgresql://localhost/dbname"
                              driverClassName="org.postgresql.Driver"
                              initialSize="5" maxWait="5000"
                              maxActive="120" maxIdle="5"
                              validationQuery="select 1"
                              poolPreparedStatements="true"/>
                </GlobalNamingResources/>
                Then, referencing the JNDI from Server's web, in context.xml server file, something like tihs, but with proper values using Hibernate
                Code:
                <ResourceLink name="DBNAME"
                   global="DBNAME"
                   type="javax.sql.DataSource"/>
                And finally delcaring JNDI bean at xml Spring configuration file:
                Code:
                <jee:jndi-lookup id="dataSource"
                		jndi-name="DBNAME"
                		resource-ref="true"/>
                If this is the correct structure, I have not been able to found the correct values for Hibernate+Tomcat-VMware Server

                And if this is not the way to use JNDI to connect with a data source, I'm still lost

                Any help with this?

                Comment


                • #9
                  I don't know how to get list of JNDI names from vFabric tc Server. But From JBoss AS, you can follow the steps from below URL.

                  http://geekzguru.wordpress.com/2008/...tree-in-jboss/

                  Comment


                  • #10
                    Don't worry, I want to thank you because you really helped me. For this last error, I'll post a new thread exclusively to treat it

                    Comment

                    Working...
                    X