-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to specify table in another database?
PostPosted: Thu Jan 27, 2005 1:17 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hibernate version: hibernate-3.0beta2, hibernate-annotations-3.0alpha2

Name and version of the database you are using: MySQL, MSSQL, Derby (I testing with all three of these and ideally whatever code I write will work with all of them by only changing hibernate.properties)

I am using Hibernate 3.0 and EJB annotations. What I want to do is have two databases. One database would contain objects like users/persons which would be shared between multiple applications. The other database would be specific to the application at hand (for example, I have one that is a reservation system and another one which deals with projects). This question is kind of annotations specific and kind of not. 1. I'm wondering if this can be done in the general case in a DBMS independent way. 2. I'm wondering how I can go about doing it using EJB annotations.

I tried using the @Table annotation which I noticed has schema and catalog attributes. What I'm wondering is what the difference is between these two attributes. I'm also wondering why there isn't a database attribute?

I tested it using the schema and catalog attributes with MySQL and found that it prepends the specified name to the name of the table with one or two underscores.

Maybe what I should be doing is using a single database with multiple schemas?

Note, the databases in question are on the same database server.

One thing that I could do which seems to work is just do the following. However, I'm not sure if that syntax is valid for all DBMSs.

@Table(name="databaseName.tableName")


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:57 pm 
Newbie

Joined: Thu Jan 20, 2005 11:01 am
Posts: 15
The actual database you connect to should be specified by selecting an appropriate Session (for example there would be Session1 for the "users" database connection and Session2 for the "project"). The database information should probably not be entered as part of the annotations otherwise you're not longer database-independent.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 11:22 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I don't think having separate sessions for each database would work for me as the objects in different databases relate to each other. For example, say I have a User object in one database and a Project object in another database and users can have projects. I would need to do queries that join the objects. I guess maybe all the objects should be in a single database and just use different schemas to keep things organized.

The other thing that I've been wondering is if Hibernate has support for distributed databases? i.e. the ability to have multiple databases on multiple different servers and be able to issue queries that join tables on different servers.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 4:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is not the job of an ORM to perform joins across separate databases.

Either do that your self (on top of multiple sessionfactories/sessions) or use a database that supports distribution.....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 2:46 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I know it's asking for a lot, I was just curious if it was possible.


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

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.