Announcement Announcement Module
Collapse
No announcement yet.
Problems with Hibernate in milestone 3 and toString in model objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with Hibernate in milestone 3 and toString in model objects

    I am using the RepeatOperationsStepConfiguration and RepeatOperationsStepConfiguration together with Hibernate with my own implementation updating a resultset with Hibernate.

    When I override the toString in the Hibernate model classes, - the process failes with the stackstrace enclosed below.

    I seems to fail with:
    org.springframework.batch.repeat.context.Synchroni zedAttributeAccessor.toString(SynchronizedAttribut eAccessor.java:151)

    Probably caused due to the Hibernate configuration which have configured the objects to be lazily loaded.

    How could I get around this?

    When I remove my own toString override, - it works....

    Geir



    2007-12-31 13:47:57,278 [DEBUG ] [main ] org.springframework.batch.repeat.support.RepeatTem plate - Exception intercepted (1 of 1)
    org.hibernate.SessionException: proxies cannot be fetched by a stateless session
    at org.hibernate.impl.StatelessSessionImpl.immediateL oad(StatelessSessionImpl.java:220)
    at org.hibernate.proxy.AbstractLazyInitializer.initia lize(AbstractLazyInitializer.java:66)
    at org.hibernate.proxy.AbstractLazyInitializer.getImp lementation(AbstractLazyInitializer.java:111)
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitialize r.invoke(CGLIBLazyInitializer.java:150)
    at no.aftenposten.accountbalancer.core.model.GeneralL edgerBean$$EnhancerByCGLIB$$da6cb6b.toString(<gene rated>)
    at java.lang.String.valueOf(String.java:2615)
    at java.lang.StringBuffer.append(StringBuffer.java:22 0)
    at org.apache.commons.lang.builder.ToStringStyle.appe ndDetail(ToStringStyle.java:545)
    at org.apache.commons.lang.builder.ToStringStyle.appe ndInternal(ToStringStyle.java:509)
    at org.apache.commons.lang.builder.ToStringStyle.appe nd(ToStringStyle.java:395)
    at org.apache.commons.lang.builder.ToStringBuilder.ap pend(ToStringBuilder.java:840)
    at org.apache.commons.lang.builder.ReflectionToString Builder.appendFieldsIn(ReflectionToStringBuilder.j ava:605)
    at org.apache.commons.lang.builder.ReflectionToString Builder.toString(ReflectionToStringBuilder.java:75 8)
    at org.apache.commons.lang.builder.ReflectionToString Builder.toString(ReflectionToStringBuilder.java:28 6)
    at org.apache.commons.lang.builder.ReflectionToString Builder.toString(ReflectionToStringBuilder.java:12 0)
    at org.apache.commons.lang.builder.ToStringBuilder.re flectionToString(ToStringBuilder.java:126)
    at no.aftenposten.accountbalancer.core.model.Abstract BaseBean.toString(AbstractBaseBean.java:41)
    at java.lang.String.valueOf(String.java:2615)
    at java.lang.StringBuffer.append(StringBuffer.java:22 0)
    at org.springframework.batch.repeat.context.Synchroni zedAttributeAccessor.toString(SynchronizedAttribut eAccessor.java:151)
    at java.lang.String.valueOf(String.java:2615)
    at java.lang.StringBuffer.append(StringBuffer.java:22 0)
    at org.springframework.transaction.support.Transactio nSynchronizationManager.getResource(TransactionSyn chronizationManager.java:140)
    at org.springframework.batch.io.support.HibernateAwar eItemWriter.getProcessed(HibernateAwareItemWriter. java:230)
    at org.springframework.batch.io.support.HibernateAwar eItemWriter.write(HibernateAwareItemWriter.java:12 1)
    at no.aftenposten.accountbalancer.batch.processor.Sub scriptionLineActivateProcessor.process(Subscriptio nLineActivateProcessor.java:38)
    at org.springframework.batch.execution.tasklet.ItemPr oviderProcessTasklet.execute(ItemProviderProcessTa sklet.java:149)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor.doTaskletProcessing(SimpleStepExe cutor.java:372)
    at org.springframework.batch.execution.step.simple.De faultStepExecutor.doTaskletProcessing(DefaultStepE xecutor.java:61)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor$2.doInIteration(SimpleStepExecuto r.java:347)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:324)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:201)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:131)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor.processChunk(SimpleStepExecutor.j ava:334)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor$1$2.doInTransaction(SimpleStepExe cutor.java:220)
    at org.springframework.transaction.support.Transactio nTemplate.execute(TransactionTemplate.java:128)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor$1.doInIteration(SimpleStepExecuto r.java:208)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:324)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:201)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:131)
    at org.springframework.batch.execution.step.simple.Si mpleStepExecutor.process(SimpleStepExecutor.java:1 85)
    at org.springframework.batch.execution.job.DefaultJob Executor.run(DefaultJobExecutor.java:97)
    at org.springframework.batch.execution.launch.SimpleJ obExecutorFacade.start(SimpleJobExecutorFacade.jav a:199)
    at org.springframework.batch.execution.launch.SimpleJ obLauncher.runInternal(SimpleJobLauncher.java:248)
    at org.springframework.batch.execution.launch.SimpleJ obLauncher$1.run(SimpleJobLauncher.java:292)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.execution.launch.SimpleJ obLauncher.run(SimpleJobLauncher.java:280)
    at no.aftenposten.accountbalancer.batch.tasklet.Abstr actBatchLauncherTests.testLaunchJob(AbstractBatchL auncherTests.java:84)
    at no.aftenposten.accountbalancer.batch.tasklet.Abstr actValidatingBatchLauncherTests.testLaunchJob(Abst ractValidatingBatchLauncherTests.java:32)
    at no.aftenposten.accountbalancer.batch.tasklet.Subsc riptionLineJobTest.testLaunchJob(SubscriptionLineJ obTest.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154 )
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.textui.TestRunner.doRun(TestRunner.java:116)
    at com.intellij.rt.execution.junit.IdeaTestRunner.doR un(IdeaTestRunner.java:65)
    at junit.textui.TestRunner.doRun(TestRunner.java:109)
    at com.intellij.rt.execution.junit.IdeaTestRunner.sta rtRunnerWithArgs(IdeaTestRunner.java:24)
    at com.intellij.rt.execution.junit.JUnitStarter.prepa reStreamsAndStart(JUnitStarter.java:118)
    at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:40)
    2007-12-31 13:47:57,313 [DEBUG ] [main ] org.springframework.batch.repeat.support.RepeatTem plate - Batch is complete according to policy and result value.
    2007-12-31 13:47:57,314 [DEBUG ] [main ] org.springframework.orm.hibernate3.SessionFactoryU tils - Opening Hibernate Session
    2007-12-31 13:47:57,315 [DEBUG ] [main ] org.hibernate.impl.SessionImpl - opened session at timestamp: 4911535215882240

  • #2
    It looks like your toString() is probably bad for your health generally, so if I were you I would re-write it to not depend on lazy-loaded properties. Otherwise you will get this kind of error anywhere when toString() is called on a detached object.

    If you really need the fragility that comes with your lazy-loaded toString() then you might try using a stateful session (it looks from the stack trace like you are using a stateless session - which takes away some of the HibernateItemWriter benefits already).

    Comment

    Working...
    X