I have two MySQL databases (version 5.0.20 and InnoDB storage engine).
I am using Hibernate 3.1, Sun Java System Application server 9.0 and Java 1.5.
I want my
orders table in my first database to have a foreign key reference to my
customers table in my second database. I have a mapping file for each table:
Customer.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="...Customer" table="...customers">
<id name="cid" type="integer" column="cid" unsaved-value="null">
<generator class="native"/>
</id>
<property name="firstName" column="firstName" not-null="true" unique="false"/>
<property name="lastname" column="lastname" not-null="true" unique="false"/>
<property name="phone" column="phone" not-null="true" unique="false"/>
<property name="address" column="address" not-null="true" unique="false"/>
<property name="email" column="email" not-null="true" unique="false"/>
</class>
</hibernate-mapping>
Order.hbm.xmlCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="...Orders" table="...orders">
<id name="oid" type="integer" column="oid" unsaved-value="null">
<generator class="native"/>
</id>
<many-to-one name="customer" column="cid" class="...Customer" cascade="all" />
<property name="description" column="description" not-null="true" unique="false"/>
<property name="amount" column="amount" not-null="true" unique="false"/>
</class>
</hibernate-mapping>
My Java Code:Code:
Configuration cfg = new Configuration();
Configuration cfg2 = new Configuration();
cfg.configure("/hibernate.cfg.xml");
cfg2.configure("/hibernate2.cfg.xml");
cfg.addClass(Customer.class);
cfg2.addClass(Order.class);
cfg2.addClass(Customer.class);
However, this is not working for me. I get the following error in my log file:Code:
2006-09-22 13:58:24,661 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] - Unsuccessful: create table ...customers (cid integer not null auto_increment, firstName varchar(255) not null, lastname varchar(255) not null, phone varchar(255) not null, address varchar(255) not null, email varchar(255) not null, primary key (cid)) type=InnoDB
2006-09-22 13:58:24,661 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] - CREATE command denied to user '...' for table 'customers'
The problem seems obvious enough, does anyone know how I can set up this foreign key without getting the error?
Any help would be much appreciated.
Torch.