Announcement Announcement Module
Collapse
No announcement yet.
JUnit + HibernateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JUnit + HibernateException

    Hi,

    I'm trying to run an update junit test method, but an exception occur. The exception occur in the bean "transactionManager".



    Code:
    org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'transactionManager' defined in class path resource [spring-hibernate.xml]: Class that bean class [org.springframework.orm.hibernate.HibernateTransactionManager] depends on not found; nested exception is java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException
    java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:87)
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:64)
    thanks

  • #2
    make sure that the class your bean refers to is in your classpath.
    If you already have, post the xml code so i can look at it.

    Comment


    • #3
      Hibernate and Spring jars are in the classpath. See de xml below:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      <beans>
      	
      	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      		<property name="configLocation">
          		<value>hibernate.cfg.xml</value>
      		</property>
      		
      	</bean>
      	
      	
      	<bean id="transactionManager"
      		class="org.springframework.orm.hibernate.HibernateTransactionManager" >
      		<property name="mySessionFactory">
      			<ref local="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="UsuarioDao" class="br.gov.pa.tj.usuario.dao.UsuarioDAOImpl">
      		<property name="mySessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="ComarcaDao" class="br.gov.pa.tj.comarca.dao.ComarcaDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="DiretorioDao" class="br.gov.pa.tj.diretorio.dao.DiretorioDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="EventoDao" class="br.gov.pa.tj.evento.dao.EventoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="EventoNaoPermitidoDao" class="br.gov.pa.tj.eventoNaoPermitido.dao.EventoNaoPermitidoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="EventoProgramaDao" class="br.gov.pa.tj.eventoPrograma.dao.EventoProgramaDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="GrupoDao" class="br.gov.pa.tj.grupo.dao.GrupoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="ModuloDao" class="br.gov.pa.tj.modulo.dao.ModuloDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="ProgramaDao" class="br.gov.pa.tj.programa.dao.ProgramaDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="ProgramaGrupoDao" class="br.gov.pa.tj.programaGrupo.dao.ProgramaGrupoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="RegistroAcessoDao" class="br.gov.pa.tj.registroAcesso.dao.RegistroAcessoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	
      	<bean id="SistemaDao" class="br.gov.pa.tj.sistema.dao.SistemaDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	
      	
      	<bean id="SistemaFacade" 
        		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        		  			<property name="transactionManager"><ref local="transactionManager"/></property>
        		  			<property name="target"><ref local="SistemaFacadeTarget"/></property>
        		  			<property name="transactionAttribute">
        		  				<props> 
        		  					<prop key="inserir*">PROPAGATION_REQUIRED</prop>
        		  					<prop key="alterar*">PROPAGATION_REQUIRED</prop>
        		  					<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
        		  				
        		  				
        		  				</props>
        		  			
        		  			
        		  			</property>
        		  			
      	
      	</bean>
      	
      	<bean id="SistemaFacadeTarget"
      		class="br.gov.pa.tj.sistema.facade.SistemaFacadeImpl">
      		<property name="SistemaDAO"><ref local="SistemaDao"/></property>
      	
      	</bean>
      	
      	<bean id="UsuarioComarcaDao" class="br.gov.pa.tj.usuarioComarca.dao.UsuarioComarcaDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      	<bean id="UsuarioGrupoDao" class="br.gov.pa.tj.usuarioGrupo.dao.UsuarioGrupoDAOImpl">
      		<property name="sessionFactory">
      			<ref bean="mySessionFactory"/>
      		</property>
      	</bean>
      </beans>
      thanks

      Comment


      • #4
        For your TransactionManager class TRY:
        class="org.springframework.orm.hibernate3.Hibernat eTransactionManager"

        That should fix this problem.

        Comment


        • #5
          Problem fixed, but....

          Code:
          org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'transactionManager' defined in class path resource &#91;spring-hibernate.xml&#93;&#58; Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException&#58; Invalid property 'mySessionFactory' of bean class &#91;org.springframework.orm.hibernate3.HibernateTransactionManager&#93;&#58; Bean property 'mySessionFactory' is not writable or has an invalid setter method&#58; Does the parameter type of the setter match the return type of the getter?
          org.springframework.beans.NotWritablePropertyException&#58; Invalid property 'mySessionFactory' of bean class &#91;org.springframework.orm.hibernate3.HibernateTransactionManager&#93;&#58; Bean property 'mySessionFactory' is not writable or has an invalid setter method&#58; Does the parameter type of the setter match the return type of the getter?
          regards

          Comment


          • #6
            HibernateTransactionManager does not have a property called mySessionFactory - it has a property called sessionFactory.

            Rob

            Comment

            Working...
            X