in memory db hibernate spring -


i have been trying integrate between spring , memorydb in junit tests keep getting exception.

org.hibernate.exception.sqlgrammarexception: user lacks privilege or object not  found:    ordertable 

testcontext.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">   <jdbc:embedded-database id="testdatasource" type="hsql"> </jdbc:embedded-database> <context:annotation-config /> <tx:annotation-driven transaction-manager="transactionmanager" /> <context:component-scan base-package="com.bidblaze.service.test"/> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">     </bean>    <!-- hibernate session factory --> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean" >     <property name="datasource">     <ref bean="testdatasource" />     </property>     <property name="packagestoscan" value= mypackage />          <property name="hibernateproperties">               <props>                     <prop key="hibernate.dialect">org.hibernate.dialect.hsqldialect</prop>                 <prop key="hibernate.hbm2ddl.auto">create-drop</prop>                 <prop key="hibernate.show_sql">true</prop>                 <prop key="hibernate.connection.url">jdbc:hsqldb:mem:projectdb</prop>              </props>         </property>    </bean>       <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager">     <property name="sessionfactory" ref="sessionfactory" />     </bean> 

with defining other beans

my service class:

                 @runwith(springjunit4classrunner.class)            @contextconfiguration(locations = { "/testcontext.xml" })            @transactional            public class testservice {         //applicationcontext context = new classpathxmlapplicationcontext(                 //"spring-config.xml");         @autowired         paypalpaymentsservice paypalservice;          @autowired         private orderdao orderdao ;         @autowired         private sessionfactory sessionfactory;         private session extsession;         @before         @transactional         public void opensessionexternal() {             extsession = sessionfactory.getcurrentsession();         }         @test         @transactional         public void shouldhaveasessionfactory() {             assertnotnull(sessionfactory);         }         @test         @transactional         public void shouldhaveasession() {             assertnotnull(extsession);         }          @test         public void saveorder(){             order order = new order();             order.setorderid("1");             order.setrecieveremail("enduser_biz@gmail.com");             order.setamount((double)2.00);             extsession.save(order);             order testorder = (order) extsession.createquery("from ordertable  orderid = ?").setparameter(0, "1").list().get(0);              assertnotnull(testorder);          } 

the order class :

    @entity     @table(name="ordertable")     public class order {  @id     @generatedvalue     @column(name="orderid") string orderid; 

ps: order class has other properties refer other classes didnt map them neither entities well. suggestions

following this answer, , knowing xml mapping, i'd suggest following annotation changes orderid:

@id @generatedvalue @column(name="orderid", columndefintion="bigint") string orderid; 

that's assuming @generatedvalue equates "native" generator in xml. might need use @genericgenerator instead strategy=native instead more this:

@id @generatedvalue(generator="my-native-generator") @genericgenerator(name="my-native-generator", strategy = "native") @column(name="orderid", columndefintion="bigint") string orderid; 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -