-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate hql join on tables with no relationship
PostPosted: Tue May 20, 2008 8:47 am 
Newbie

Joined: Tue May 20, 2008 5:38 am
Posts: 3
Location: KSA
I need to run some read only reports by joining the following two tables:

1) payments
2) subscriptions

The join will be on a column in both called paymentreference.
I do not have control over the underlying database and the two tables and the two tables do not have a relationship i.e. no foreign keys exist.

Is it possible to add the relationship primary and foreign key in the annotations for the pojos and then use hql to perform the join even though there are no keys in the database? At the moment we are using a native sql query and using a results transformer to map the results to a pojo.

I am using hibernate 3.2 annotations.

Thanks in advance

Abu


Top
 Profile  
 
 Post subject: Re: Hibernate hql join on tables with no relationship
PostPosted: Tue May 20, 2008 9:08 am 
Newbie

Joined: Tue May 20, 2008 6:54 am
Posts: 3
Location: Indonesia
cf0051 wrote:
I need to run some read only reports by joining the following two tables:

1) payments
2) subscriptions

The join will be on a column in both called paymentreference.
I do not have control over the underlying database and the two tables and the two tables do not have a relationship i.e. no foreign keys exist.

Is it possible to add the relationship primary and foreign key in the annotations for the pojos and then use hql to perform the join even though there are no keys in the database?


Im not too understand with your problem, but why don't you try to get two tables first and then take the columns you need? I mean do getPayment and getSubscription first and then take the columns you need for reports.

I think it's not right to add relationship in your pojo while it doesn't exist in your real table, you create your pojo based on your database design.

is paymentreference column is exists in your 2 tables? so what is the content of that column? sorry I don't too understand with your needs ^!^

_________________
^0^


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 2:32 pm 
Newbie

Joined: Tue Apr 25, 2006 1:17 pm
Posts: 19
Do you want to do something like:

Code:
'from Payments p, Subscriptions s where p.paymentreference = s.paymentreference'


where the above is query that you're running after you have a session:
Code:
Query query = session.createQuery(aboveQuery)
List result = query.list()


Essentially, you're performing a join on the two tables using the paymentreference column although there's no referential integrity built into the tables..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.