Results 1 to 6 of 6

Thread: DAO Test case not commiting data to DB

  1. #1
    Join Date
    Sep 2007
    Posts
    13

    Default DAO Test case not commiting data to DB

    Hi,

    I have a simple Unit Test which asserts the hibernateTemplate.save(obj).
    I am using oracle 10g and hibernate 2.

    Assertion succeeds, but when i go and look into the database, i do not see that row! Appreciate if someone can help! thx in advance

    here is my setup code

    protected HibernateTemplate hibernateTemplate;

    protected void setUp() throws Exception {
    Configuration configuration = new Configuration();
    configuration.setProperty(Environment.DRIVER,"orac le.jdbc.driver.OracleDriver");
    configuration.setProperty(Environment.URL,"jdbc:or acle:thin:@localhost:1521:orcl");
    configuration.setProperty(Environment.USER, "scott");
    configuration.setProperty(Environment.PASS, "tiger");
    configuration.setProperty(Environment.DIALECT,net. sf.hibernate.dialect.Oracle9Dialect.class.getName( ));
    configuration.setProperty(Environment.SHOW_SQL, "true");
    //configuration.setProperty(Environment.HBM2DDL_AUTO , "create-drop");
    configuration.addResource("hbm/abc.hbm.xml");
    SessionFactory sessionFactory = configuration.buildSessionFactory();

    hibernateTemplate = new HibernateTemplate(sessionFactory);
    hibernateTemplate.flush();
    }

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is it possible to see the full testCase, if you wrap it in [code] [ /code] tags it's sooo much easier to read! It would also be useful to turn up the logging.
    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
    Sep 2007
    Posts
    13

    Default

    Hi, thx for willing to help. The assert succeeds. I am prinitng the id and i see a new prim key (sequence) generated

    Code:
     
    public abstract class HibernateTestCase extends TestCase {
    	protected HibernateTemplate hibernateTemplate;
    
    	protected void setUp() throws Exception {
    		Configuration configuration = new Configuration();
            configuration.setProperty(Environment.DRIVER,"oracle.jdbc.driver.OracleDriver");
            configuration.setProperty(Environment.URL,"jdbc:oracle:thin:@localhost:1521:orcl");
            configuration.setProperty(Environment.USER, "scott");
            configuration.setProperty(Environment.PASS, "tiger");
            configuration.setProperty(Environment.DIALECT,net.sf.hibernate.dialect.Oracle9Dialect.class.getName());
            configuration.setProperty(Environment.SHOW_SQL, "true");
            //configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
            configuration.addResource("hbm/acro.hbm.xml");        SessionFactory sessionFactory = configuration.buildSessionFactory();
    
            hibernateTemplate = new HibernateTemplate(sessionFactory);
            hibernateTemplate.flush();
    	}
    
    	public abstract Class getMappingClassUnderTest();
    }
    Test Case
    Code:
     
    public class HibernateAcro50DaoImplTest extends HibernateTestCase {
    
    	private BasicHibernateDao acro50Dao = new BasicHibernateDao();
    	private BasicAcro50CatalogableEntry acro50 = new BasicAcro50CatalogableEntry();
    
    	protected void setUp() throws Exception {
    		super.setUp();
    		acro50Dao.setHibernateTemplate(hibernateTemplate);
    	}
    
    	public void testSave() {
    Long id = acro50Dao.save(acro50);
    		System.out.println("ID = "+id);
    		assertNotNull(id);
    	}

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Seems a strange one, is there anything in the logs?
    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.

  5. #5
    Join Date
    Sep 2007
    Posts
    13

    Default

    nope nothing in the logs except a select statement for the sequrnce number and an "insert sql" statement to insert the row!

  6. #6
    Join Date
    Sep 2007
    Posts
    13

    Default not able to figure out yet!

    Hi can anyone help here pls!

Posting Permissions

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