Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using hibernate with tables have no relation

 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ??
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • 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,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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 ]
 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm , so i need to do it with the hard way and without Hibernate
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • 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 ]
 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic