I am trying to create a test database in my spring application using the tag to create it. However, when I try to access the database I get the following exception:
org.hsqldb.HsqlException: user lacks privilege or object not found: PRODUCT
I have it declared as follows:
<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>
and here are my sql files:
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 pr开发者_开发知识库7.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);
and this is the class that is accessing it
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();
}
}
The exception is thrown on the return line.
Any help on how I can get this working?
Most likely the schema name PR7 is being ignored and it looks for PRODUCT table in the default PUBLIC schema.
精彩评论