• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

using hibernate with tables have no relation

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can hibernate be used in 2 tables without any relation or association between them ? or hibernate must be used only with tables got primary and foreign keys between them ??
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sherif, you mean that these two tables doesn't have a foreign key constraint from one to the other or that doesn't have anything in common not even a single row,

regards,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sherif Shehab:
Hi,
Can hibernate be used in 2 tables without any relation or association between them ? or hibernate must be used only with tables got primary and foreign keys between them ??



Yes. You can apply arbitary relationships via HQL on unrelated fields, just as you can in SQL. Support for unions (which are the only valid join accross unrelated tables) are not there yet. But if you absolutely had to do them Hibernate support SQL too.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Angel Taveras:
Hello Sherif, you mean that these two tables doesn't have a foreign key constraint from one to the other or that doesn't have anything in common not even a single row,

regards,



HI , no i mean that these two tables doesn't have a foreign key constraint from one to the other, what i'm thinking in that table A in db1 , table B in db2 , the last table will be a backup for table A , so there is no foreign or primary keys between them or any associations ... got me ?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


what i'm thinking in that table A in db1 , table B in db2 ,


No, Hibernate cannot do this. Hibernate is primarily designed to work with relational data. As soon as you stray from relational data you start to have problems.

You can do it with database specific functionality: some databases allow you to define a logical database that spans more than one actual database (Oracle for example allows you to access one databse from another using linking).

However what you suggest sounds like it would be better achieved using the database's own replication mecahnism and keep a (presumably hot?) backup that way.
[ December 23, 2008: Message edited by: Paul Sturrock ]
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm , so i need to do it with the hard way and without Hibernate
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'd argue that using the database replication mechanism supplied with your database is the easy way and trying to do this through an ORM is the hard way.
 
Angel Taveras
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Paul it's very hard to make it work with an ORM. Sherif why do you want to make a join or make a relationship with these two tables if they contain the same data? Maybe if you can tell us a little about what you're trying to do with it we can come with a recommendation,

regards,
[ December 24, 2008: Message edited by: Angel Taveras ]
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Angel Taveras:
I agree with Paul it's very hard to make it work with an ORM. Sherif why do you want to make a join or make a relationship with these two tables if they contain the same data? Maybe if you can tell us a little about what you're trying to do with it we can come with a recommendation,

regards,

[ December 24, 2008: Message edited by: Angel Taveras ]



actually the goal i wanna reach is to back up a table for instance named table1 in db1 in table2 in db2 , so how i can do any relation and the 2 tables in different DBs ? any recommendations
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sherif Shehab wrote:

Originally posted by Angel Taveras:
I agree with Paul it's very hard to make it work with an ORM. Sherif why do you want to make a join or make a relationship with these two tables if they contain the same data? Maybe if you can tell us a little about what you're trying to do with it we can come with a recommendation,

regards,

[ December 24, 2008: Message edited by: Angel Taveras ]



actually the goal i wanna reach is to back up a table for instance named table1 in db1 in table2 in db2 , so how i can do any relation and the 2 tables in different DBs ? any recommendations



Why do they need to be related? And if they are related, should they not be in the same schema?

Database backups are something databases have been doing years before Hibernate existed. Just use the tools your database provides. Which database are you using?
 
reply
    Bookmark Topic Watch Topic
  • New Topic