Announcement Announcement Module
Collapse
No announcement yet.
Not able to understand hibernate exception reason Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not able to understand hibernate exception reason

    i am using hibernate template to save date.after data is saved,while leaving the hibernate .i am getting this exception.i am using cglib proxy for Spring Aop Proxy object..if i dont instantiate this persistent bean in the spring context file than this is working fine.so problem look somewhere with persistence of the proxy object in the database...can anyone provide solution to this

    i have tried to google this ,but cudnt find correct solution for this problem
    problem look similar to this.


    we are invoking transaction in the service layer and all the methods are declared in the dao layer.one more problem is that i am not able to catch this exception.because this hibernate transaction manager commit is going out of scope.


    service layer
    Code:
    Transactional(propagation = Propagation.REQUIRES_NEW)
    	public void invokeService()  {
    	
    		
    		
    			try {
    //var 1 and var 2 are  spring bean
    				dao.addex1(var1, var2);
    				dao.addex2(var1, var2,);
    				dao.addEx3(var1, var2);
    				
    			} catch (CustomException e) {
    				System.out.println("i m here");
    				e.printStackTrace();
    			}



    spring config file
    Code:
     <bean id="var1" class="com.ex.exc.d.exClass" />
    
                <aop:aspectj-autoproxy proxy-target-class="true"/>
    	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
      <bean id="interceptor" class="com.ex.ex3.dao.UnCGLIBInterceptor"></bean>
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="mappingDirectoryLocations">
    			<list>
    				<value>classpath:/resources/hibernate-mappings</value>
    			</list>
    		</property>
    		<property name="dataSource">
    			<ref local="exampleDataSource" />
    		</property>
    		<property name="hibernateProperties">
    			<ref bean="exampleHibernateProperties" />
    		</property>
    		<property name="entityInterceptor">
               <ref local="interceptor"/>
            </property>
    		
    	</bean>
        
    	<bean id="exampleDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="driverClassName">
    			<value>com.ibm.db2.jcc.DB2Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:db2://4.cc.00.00:50001/XC128086</value>
    		</property>
    		<property name="password">
    			<value>pas$</value>
    		</property>
    		<property name="username">
    			<value>past</value>
    		</property>
    	</bean>
    
    	<bean id="exampleHibernateProperties"
    		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    		<property name="properties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
    				<prop key="hibernate.hbm2ddl.auto">update</prop>
    				<prop key="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext
    				</prop>
    				<prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
    				</prop>
    				<prop key="c3p0.acquire_increment">3</prop>
    				<prop key="c3p0.max_size">30</prop>
    				<prop key="c3p0.min_size">3</prop>
    				<prop key="c3p0.max_statements">0</prop>
    				<prop key="c3p0.idle_test_period">0</prop>
    				<prop key="c3p0.timeout">0</prop>
    				<prop key="current_session_context_class">thread</prop>
    				<prop key="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
    				<prop key="connection.autocommit">true</prop>
    				<prop key="show_sql">false</prop>
    				<prop key="format_sql">false</prop>
    				<prop key="use_sql_comments">false</prop>
    				<prop key="hibernate.show_sql">false</prop>
    			</props>
    		</property>
    	</bean>

    transaction manger
    Code:
    <tx:annotation-driven transaction-manager="transactionManager"  proxy-target-class="true"/>
    
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>

    Exception Code
    Code:
    48:24,022  INFO Certificate:111 - [ leaving < getCertificateId > returning 70F9C2B7-C443-4AE6-A3F8-F87CCC5CF2A0 ]
    11:48:24,022  INFO Certificate:111 - [ leaving < getTrsSequenceNbr > returning 0 ]
    11:48:24,412  WARN JDBCExceptionReporter:100 - SQL Error: -407, SQLState: 23502
    11:48:24,412 ERROR JDBCExceptionReporter:101 - DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=4, COLNO=4, DRIVER=3.50.152
    11:48:24,428 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
    org.hibernate.exception.ConstraintViolationException: could not insert: [com.tcs.ert.dffdfdf.domain.Certificate]
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    	at 
    	at 
    	at resources.rules.Rule_Add_Certificate_0DefaultConsequenceInvoker.evaluate(Rule_Add_Certificate_0DefaultConsequenceInvoker.java:29)
    	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917)
    	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:856)
    	at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1071)
    	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:785)
    	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:751)
    	at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
    	at com.csc.exceed.infrastructure.BusinessProcessManager.executeUOWSequence(BusinessProcessManager.java:57)
    	at com.csc.exceed.infrastructure.BusinessProcessManager$$FastClassByCGLIB$$9b340517.invoke(<generated>)
    	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    	at
    Last edited by vishal1398; Apr 14th, 2011, 01:21 AM. Reason: More elaborate problem

  • #2
    Hello

    1) use code tags, use more readable for us
    2) post here your configuration to have a clear idea about what you are doing

    Comment


    • #3
      Your configuration is flawed... Use the search for more information.

      Code:
      <bean id="exampleHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
      	<property name="properties">
      		<props>
      			<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
      			<prop key="hibernate.hbm2ddl.auto">update</prop>
      			<prop key="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext
      			</prop>
      			<prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
      			</prop>
      			<prop key="c3p0.acquire_increment">3</prop>
      			<prop key="c3p0.max_size">30</prop>
      			<prop key="c3p0.min_size">3</prop>
      			<prop key="c3p0.max_statements">0</prop>
      			<prop key="c3p0.idle_test_period">0</prop>
      			<prop key="c3p0.timeout">0</prop>
      			<prop key="current_session_context_class">thread</prop>
      			<prop key="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
      			<prop key="connection.autocommit">true</prop>
      			<prop key="show_sql">false</prop>
      			<prop key="format_sql">false</prop>
      			<prop key="use_sql_comments">false</prop>
      			<prop key="hibernate.show_sql">false</prop>
      		</props>
      	</property>
      </bean>
      The stuff in blue is useless as you are injecting a DataSource, the stuff in red break proper transaction management with spring (as I stated use the forum search for more information as that question has been answered numerous times before).

      next to that don't catch ans swallow the exception, which you do in your service, this also breaks proper tx management. The transaction advice never sees the exception, so never rollsback but always tries to commit.

      Finally why on earth would you define your entities for your database in a spring configuration file?!

      Comment


      • #4
        Thanks a lot for your suggestion.. i will be helpful if u can put more light on the correct hibernate properties that are required in this project.

        i tried on forum bt cudnt get satisfactory result.

        i am defining db entities in the spring config file since we need spring AOP logging support for these entities.so these entities need to be instantiated by the spring container.

        when these entities are not defined in the spring config file..transaction is working fine..

        i will looking for your futher inputs as i am newbie in this field

        Comment


        • #5
          Even if you define them in your spring context they aren't going to be adviced, hibernate is completly ignoring those settings when entities are loaded from the database. So basically that configuration is useless. (As stated remove the red and blue items to fix transactions).

          I fyou want aop on your entities you will have to use a full blown aop solution like AspectJ and use loadtime or compile time weaving. The proxy based approach from spring isn't going to work.

          Comment


          • #6
            Martin i have removed the properties that you have highlighted.but still problem remains

            do you think defining entities in the spring config file can also create problem in transaction

            i am able to log the getter setter of these pojos using the spring Aop and defining them in the spring config file,so logging is happening but this transaction erxception is occuring

            Comment


            • #7
              It is only happening for the 2 instances defined in your xml, if you would store them in the databse and load them from the database there is no logging (trust me in this)... So as I stated remove them as it isn't doing anything for the entities in your database...

              You get an exception because some constraint is violated, not sure what your dao does and or your logger (I suspect the last is breaking your code). But as I already stated your configuration is useless as it will only work for the 2 entries defined in your xml, for other entries it will not work.

              Comment


              • #8
                hmm... i will do the same.. i think logger is throwing the exception..when i am not using the transactional annotation over the invoke method i am getting following error

                Code:
                used by: java.lang.IllegalAccessException: Class org.exolab.castor.mapping.loader.FieldHandlerImpl can not access a member of class org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl with modifiers "public"
                	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
                	at java.lang.reflect.Method.invoke(Method.java:588)
                	at org.exolab.castor.mapping.loader.FieldHandlerImpl.getValue(FieldHandlerImpl.java:417)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1843)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1997)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:2004)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:2004)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:2004)
                	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:914)
                	at org.springframework.oxm.castor.CastorMarshaller.marshal(CastorMarshaller.java:332)
                	at org.springframework.oxm.castor.CastorMarshaller.marshalWriter(CastorMarshaller.java:318)
                	at org.springframework.oxm.AbstractMarshaller.marshalStreamResult(AbstractMarshaller.java:256)
                	at org.springframework.oxm.AbstractMarshaller.marshal(AbstractMarshaller.java:97)
                	at com.csc.exceed.util.OXMapper.loadObjectsToXML(OXMapper.java:60)
                	at com.csc.exceed.util.OXMapper$$FastClassByCGLIB$$f1923224.invoke(<generated>)
                	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
                	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
                	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
                	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
                	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:77)
                	at com.csc.exceed.aspect.logging.LoggingAspect.aroundAdvice(LoggingAspect.java:149)
                	at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
                	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                	at java.lang.reflect.Method.invoke(Method.java:597)
                	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627)
                	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616)
                	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:64)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
                	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
                	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
                	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
                	at com.csc.exceed.util.OXMapper$$EnhancerByCGLIB$$9b2ac9e5.loadObjectsToXML(<generated>)
                	at com.csc.exceed.controller.ControllerServlet.doPost(ControllerServlet.java:120)
                	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
                	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                	at java.lang.Thread.run(Thread.java:619)

                Comment


                • #9
                  Not sure what you are trying to do, but the enhanced objects have additional properties, next to the fact that the classname is generated dynamically which might be problematic for xmlbeans (not sure though).

                  Comment


                  • #10
                    Hi Martin,
                    as suggested i am using AspectJ in SpringSource Tool..
                    but i am not to able laod domain objects.. i am facing problem already shared as following link.http://forum.springsource.org/showthread.php?t=108786

                    it will very helpful if you can guide me overthat

                    Comment

                    Working...
                    X