Results 1 to 3 of 3

Thread: HSQL error

  1. #1

    Default HSQL error

    Hi,

    I am trying to create an in-mem database using HSQL. I have the Hibernate layer setup for all my tables in a .xml file.

    I set up the schema using the CREATE SCHEMA command in HSQL
    I am not able to persist changes;
    HibernateUtil.commitTransaction() does NOT WORK!!

    It gives me a Batchupdate error!

    I would appreciate if someone could help me out with this. Pl.!

  2. #2
    Join Date
    Apr 2006
    Location
    Montreal, Canada
    Posts
    178

    Default

    We could help you more if you posted your code, application context and stack trace using the [ code][/code ] tags. Also this is a Spring forum so you might have more luck posting this to a Hibernate forum

    Cheers,
    GB

  3. #3

    Thumbs up My Code!

    Code:
     @RunWith(JMock.class)
               public class XTest{
               private Mockery mm;
               private static Session ss;
               private X xx;
               private final String string = getRandomString();
               private static final String JDBC_URL = "jdbc:hsqldb:mem:SCHEME";
    
               @Before
                public void setUp(){
                mm = new JUnit4Mockery();   
                ss = mm.mock(Session.class);
                xx = new X();
                
                Class.forName("org.hsqldb.jdbcDriver");
                Connection conn = DriverManager.getConnection(JDBC_URL,"sa","");
                Statement st = conn.createStatement();
                String expression = "CREATE SCHEMA SCHEME AUTHORIZATION DBA";
                st.executeUpdate(expression);
               /* Am lil doubtful abt this */ 
               expression = "CREATE SCHEMA dual_SCHEME AUTHORIZATION DBA"; 
                st.executeUpdate(expression);
                st.close();
                conn.close();
    
                Configuration cfg = new Configuration().configure("abc.xml");
                HibernateUtil.setSessionFactory(cfg.buildSessionFactory())  ;
     }
    
              /*   This test seems to be not working!!  */
              public void testSaveandGetX(){
                    X x = getRandomX();
                    x.setStr1(string);
                    save(x);
                    HibernateUtil.begintransaction();
                    /* This returns a null object!! */
                    X ret = xx.getXwithStr1(string);
                    Assert.assertEquals(string,ret.getStr1);                   
                    HibernateUtil.commitTransaction(); 
               }
                 
               public void save(X x){
                      HibernateUtil.beginTransaction();
                      session.save(x);
                      HibernateUtil.commiTransaction(); /* Throws an exception! Not               able to commit*/
                }
     
                public void getXwithStr1(String s){
                /* This call also fails!*/
                 X x = (X)HibernateUtil.getSession().createCriteria(Newspaper.class).add(Expression.eq("Str1",s)).uniqueResult();
                 return x;
    
                 } 
    
    }   
     /*       X.hbm.xml      */
       /*
              Add all the hibernate includes!
       */       
            <class name="X" table="SCHEME.X">
            <id name="id" column="X_ID" type="long">
             <generator class = "sequence">
                    <param name="sequence">SCHEME.X_SEQ</param>
              </generator>
              </id>
    
              <property name="Str1" column="Str1" not-null="true" />
               <set name ="sections" inverse="true" cascade="all-delete-orphan" lazy="true">
                <key column="X_ID" not-null="true"/>
                 <one-to-many class="XSection" />
                </set>
            
              /* XSection.hbm.xml */
             /*
                    Add all the hibernate includes              
     
             */
               <class name="XSection" table="SCHEME.XSection">
                     <id name="id" column="XSection_ID" type="long">
                          <generator class="sequence">
                                   <param name="sequence">SCHEME.XSection_SEQ</param>
                           </generator>
                       </id>
                 <many-to-one name="par" column="X_ID" class="X" not-null="true" />
                 <property name="mark" column="MARK" type="long" not-null="true" />
    
                 </class>
    For some reason, I am not able to commit the Transaction!. I am not able to retrieve the data. I feel there is something wrong in the creation of my schema in HSQL.
    I would really appreciate if someone could help me out with this! Pl.

    Thanks
    Vivek

Posting Permissions

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