Results 1 to 3 of 3

Thread: AbstractTransactionalDataSourceSpringContextTests VS standalone application

  1. #1
    Join Date
    Jul 2005
    Location
    Bordeaux
    Posts
    27

    Question 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You are using the transactional Spring test classes, I would recommend not using a transaction and seeing if the behaviour is the same.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jul 2005
    Location
    Bordeaux
    Posts
    27

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •