-->
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: Logical Relationship between tables
PostPosted: Tue Aug 25, 2015 3:48 am 
Newbie

Joined: Thu Mar 05, 2009 11:17 am
Posts: 5
Hi,

I have a general question about the the table relation.

Suppose I have two tables A & B and there is no relation between them in database.
Even in the generated .hbm file also there is no relationship.

But, if I manually put a "one to many" relation between table A & B in the .hbm file and entity class, will it work ?
Can I join the tables using HQL ?


Thanks in Advance,
Anish


Top
 Profile  
 
 Post subject: Re: Logical Relationship between tables
PostPosted: Tue Aug 25, 2015 4:48 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
No, it won't work without changing the database (if that's what you are asking).

Hibernate needs to store the information about the relationship between the two tables somewhere. It might be some column(s) on one of the tables or a joining table.

Hibernate should be able to create the required column(s) or table at startup, if you set the property "hibernate.hbm2ddl.auto" to "update".

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: Logical Relationship between tables
PostPosted: Tue Aug 25, 2015 5:31 am 
Newbie

Joined: Thu Mar 05, 2009 11:17 am
Posts: 5
Hi,

Thanks for your reply.

In my scenario, the database is in production and maintaining by a third party, they won't allow us to make the relationships between the tables.

I thought if I can specify the required relations in .hbm and entity class (without modifying the database), I will be able to specify joins using Criteria/HQL in order to get the linked Entity class instances.

Is there any other way to achieve the same?

Thanks and Regards,
Anish


Top
 Profile  
 
 Post subject: Re: Logical Relationship between tables
PostPosted: Tue Aug 25, 2015 6:49 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
You might be able to write the HQL/Criteria query, but Hibernate will then convert it into an SQL one and it will execute it on the DB.

I don't see how this could work if you don't store the relationship on the DB in some way.

> In my scenario, the database is in production and maintaining by a third party, they won't allow us to make the relationships between the tables.

What kind of changes can you apply to the database? Can you create a new table?


Top
 Profile  
 
 Post subject: Re: Logical Relationship between tables
PostPosted: Tue Aug 25, 2015 6:59 am 
Newbie

Joined: Thu Mar 05, 2009 11:17 am
Posts: 5
Hi,

Thank you very much for your prompt reply.

We have got only read only access to the database.

So we cannot even execute a create table script !

Thanks & Regards,
Anish


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.