Announcement Announcement Module
Collapse
No announcement yet.
AbstractTransactionalDataSourceSpringContextTests VS standalone application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractTransactionalDataSourceSpringContextTests VS standalone application

    Hi spring folks,

    I am facing a small probem I can not figure out... I have a piece of code that runs smoothly when unit tested (it extends AbstractTransactionalDataSourceSpringContextTests) but fails when I try to run it in stand alone program with a main(...) method. Can someone give me a hint please? Any pointers are warmly welcome...
    Thanks.

    here is the code :

    <<<<<<<<<<<<<
    public class SecurityTest extends
    AbstractTransactionalDataSourceSpringContextTests {

    PatientManager mgr;

    public SecurityTest() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
    new String[] { "classpath:/applicationContext-*.xml" });
    mgr = (PatientManager) ctx.getBean("patientManager");
    }

    protected String[] getConfigLocations() {
    return new String[] { "classpath:/applicationContext-*.xml" };
    }

    public void setPatientManager(PatientManager mgr) {
    this.mgr = mgr;
    }

    public void testMe() {
    doTheJob();
    }

    public static void main(String[] args) throws Exception {
    new SecurityTest().doTheJob();
    }

    private void doTheJob() {
    Patient p = mgr.getPatient(1L);
    mgr.savePatient(p);
    }

    }
    >>>>>>>>>>>>

    here is the Exception i get when launching main method :
    <<<<<<<<<<<<
    [conticabase] ERROR [main] AssertionFailure.error(119) | an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
    org.hibernate.AssertionFailure: collection [org.rca.conticabase.model.AnnotationAttribute.allo wed] was not processed by flush()
    at org.hibernate.engine.CollectionEntry.postFlush(Col lectionEntry.java:205)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.postFlush(AbstractFlushingEventListener.java:3 33)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:28)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:373)
    at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:686)
    at org.rca.conticabase.dao.hibernate.PatientDaoHibern ate.savePatient(PatientDaoHibernate.java:64)
    at org.rca.conticabase.service.impl.PatientManagerImp l.savePatient(PatientManagerImpl.java:61)
    at org.rca.conticabase.util.SecurityTest.doTheJob(Sec urityTest.java:40)
    at org.rca.conticabase.util.SecurityTest.main(Securit yTest.java:35)
    Exception in thread "main" org.hibernate.AssertionFailure: collection [org.rca.conticabase.model.AnnotationAttribute.allo wed] was not processed by flush()
    at org.hibernate.engine.CollectionEntry.postFlush(Col lectionEntry.java:205)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.postFlush(AbstractFlushingEventListener.java:3 33)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:28)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:373)
    at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:686)
    at org.rca.conticabase.dao.hibernate.PatientDaoHibern ate.savePatient(PatientDaoHibernate.java:64)
    at org.rca.conticabase.service.impl.PatientManagerImp l.savePatient(PatientManagerImpl.java:61)
    at org.rca.conticabase.util.SecurityTest.doTheJob(Sec urityTest.java:40)
    at org.rca.conticabase.util.SecurityTest.main(Securit yTest.java:35)
    >>>>>>>>>>>>

  • #2
    You are using the transactional Spring test classes, I would recommend not using a transaction and seeing if the behaviour is the same.

    Comment


    • #3
      Thanks for answering karldmoore.
      Actually if I set my unit test to inherit from AbstractDependencyInjectionSpringContextTests then the test fails just like the main method does (same Exception)...
      Any idea how to solve this problem and have the standalone program working?
      Thanks.

      Comment

      Working...
      X