-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping across two databases
PostPosted: Fri Sep 22, 2006 2:35 am 
Newbie

Joined: Thu Sep 07, 2006 9:33 pm
Posts: 4
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.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="...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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.