2011-07-21 75 views
0

我想創建一個測試數據庫在我的春天應用程序使用標記來創建它。然而,當我嘗試訪問我得到下面的異常數據庫:jdbc:嵌入式數據庫拋出HsqlException

org.hsqldb.HsqlException: user lacks privilege or object not found: PRODUCT 

我把它聲明如下:

<jdbc:embedded-database id="dataSource"> 
    <jdbc:script location="classpath:schema.sql"/> 
    <jdbc:script location="classpath:test-data.sql"/> 
</jdbc:embedded-database> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan" value="com.blah.domain" /> 
</bean> 

,這裏是我的SQL文件:

create schema pr7; 

create table pr7.package_type (
    id bigint primary key , 
    description varchar(255), 
    type varchar(255), 
    version int 
); 

create table pr7.product (
    id bigint primary key, 
    ca_product varchar(255), 
    description varchar(255), 
    product_id varchar(255), 
    product_name varchar(255), 
    package_type bigint, 
    version int, 
    end_date date, 
    start_date date, 
    foreign key (package_type) references package_type(id) 
); 

create table pr7.upgrade_type (
    id bigint primary key, 
    description varchar(255), 
    type varchar(255), 
    version int 
); 

create table pr7.upgrade (
    id bigint primary key, 
    description varchar(255), 
    name varchar(255), 
    upgrade_type bigint, 
    version int, 
    foreign key (upgrade_type) references upgrade_type(id) 
); 

create table pr7.upgrade_product (
    product_id bigint, 
    upgrade_id bigint, 
    foreign key (product_id) references product(id), 
    foreign key (upgrade_id) references upgrade(id), 
    primary key (product_id, upgrade_id) 
); 

create table pr7.user_role (
    id bigint primary key , 
    description varchar(255), 
    type varchar(255), 
    version int 
); 
create table pr7.rules_user (
    id bigint primary key, 
    domain_account bit, 
    fullname varchar(255), 
    password varchar(255), 
    username varchar(255), 
    user_role bigint, 
    version int, 
    foreign key (user_role) references user_role(id) 
); 

insert into pr7.package_type (id, description, type) values (1, 'PackageType 1', 'PackageType 1'); 
insert into pr7.package_type (id, description, type) values (2, 'PackageType 2', 'PackageType 2'); 

insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (1, 'Product 1', 'Product 1', 'Prod1', 'Product 1', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (2, 'Product 2', 'Product 2', 'Prod2', 'Product 2', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (3, 'Product 3', 'Product 3', 'Prod3', 'Product 3', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (4, 'Product 4', 'Product 4', 'Prod4', 'Product 4', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (5, 'Product 5', 'Product 5', 'Prod5', 'Product 5', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (6, 'Product 6', 'Product 6', 'Prod6', 'Product 6', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (7, 'Product 7', 'Product 7', 'Prod7', 'Product 7', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (8, 'Product 8', 'Product 8', 'Prod8', 'Product 8', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (9, 'Product 9', 'Product 9', 'Prod9', 'Product 9', 1); 
insert into pr7.product (id, ca_product, description, product_id, product_name, package_type) values (10, 'Product 10', 'Product 10', 'Prod10', 'Product 10', 1); 

insert into pr7.upgrade_type (id, description, type) values (1, 'UpgradeType 1', 'UpgradeType 1'); 
insert into pr7.upgrade_type (id, description, type) values (2, 'UpgradeType 2', 'UpgradeType 2'); 

insert into pr7.upgrade (id, description, name, upgrade_type) values (1, 'Upgrade 1', 'Upgrade 1', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (2, 'Upgrade 2', 'Upgrade 2', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (3, 'Upgrade 3', 'Upgrade 3', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (4, 'Upgrade 4', 'Upgrade 4', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (5, 'Upgrade 5', 'Upgrade 5', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (6, 'Upgrade 6', 'Upgrade 6', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (7, 'Upgrade 7', 'Upgrade 7', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (8, 'Upgrade 8', 'Upgrade 8', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (9, 'Upgrade 9', 'Upgrade 9', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (10, 'Upgrade 10', 'Upgrade 10', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (11, 'Upgrade 11', 'Upgrade 11', 1); 
insert into pr7.upgrade (id, description, name, upgrade_type) values (12, 'Upgrade 12', 'Upgrade 12', 1); 

insert into pr7.upgrade_product (upgrade_id, product_id) values (1, 1); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (2, 2); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (3, 3); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (4, 4); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (5, 5); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (6, 6); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (7, 7); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (8, 8); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (9, 9); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (10, 10); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (11, 1); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (11, 2); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 1); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 2); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 3); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 4); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 5); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 6); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 7); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 8); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 9); 
insert into pr7.upgrade_product (upgrade_id, product_id) values (12, 10); 

並且這是訪問它的類

public class HibernateProductDao implements ProductDao{ 
{ 
    @Autowired 
    private SessionFactory sessionFactory; 

    @Override 
    public List<Product> getProducts() { 
     Session session = sessionFactory.getCurrentSession(); 
     return (List<Product>)session.createQuery("from Product").list(); 
    } 
} 

返回行發生異常。

任何幫助我如何才能得到這個工作?

+1

最有可能的架構名稱PR7被忽略,它在默認的PUBLIC架構中查找PRODUCT表 – fredt

+0

如果您可以添加此答案我可以接受它 – Xetius

+0

完成,我希望有人可以展示如何指定PR7您的Hibernte/Spring設置中的模式。 – fredt

回答

1

最有可能的架構名稱PR7被忽略,它在默認的PUBLIC架構中查找PRODUCT表。