-->
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.  [ 13 posts ] 
Author Message
 Post subject: Mapping class to 2 tables problem!
PostPosted: Fri Apr 02, 2004 5:21 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
Hi,

I have a class that is mapped to table A, and one of the class properties needs to be retrieved from table B.

Can i define such property in the class map file?

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 5:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Try using a formula property, with a subselect.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 5:55 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
gavin wrote:
Try using a formula property, with a subselect.


Sorry, i am not sure i understand what you mean. Could you please explain a bit more?

Thanks

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
a property can be built based on a SQL formula, do do the appropriate SQL to get the B column.
<property name="toto" formula="select b from tableB where.../>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 2:11 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi emmanuel,
formula= "select b from tableB where..." ok but is it possible in this query to interact with internal field
example formula= "select b from tableB where table B= this.attribut????"


thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 8:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
<property
    name = "property"
    formula = "(select b.column from tableB b where b.id= thisIdColumn)"/>


Of course, the property won't be updateable...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 3:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
very very interesting, i'll try this very soon.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 3:31 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
emmanuel wrote:
a property can be built based on a SQL formula, do do the appropriate SQL to get the B column.
<property name="toto" formula="select b from tableB where.../>


Thank you ever so much. I will try it.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
this feature is working great!!!
how can i "protect" string.
i want my formula to call an oracle fonction, this works perfectly when arguments of this fonction are numbers but when one of the argument is "sysdate", the generated sql become ALIAS.sysdate :(


Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, why not provide a patch to Hibernate. Some of the Dialects now have knowledge of the SQL functions available on that platform.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. look at net.sf.hibernate.sql.Template


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if you think it is safe to add keyword "sysdate" to Set KEYWORDS of Template.java, i'll provide a patch, i'll also try to find if other "keywords" (supported by most of db) can be added.
The only danger will be to have:
- a db that does not support the keyword
- a column name like the keyword
In fact the most secure would be to have one KEYWORDS Set per dialect or to protect specific db keywords by specials characters ... (for example write "#sysdate#" in place of 'sysdate'

I also notice that if we enter formula="DECODE (....)", it generates ALIAS.DECODE because of the space between DECODE and '(', so it could be helpful to detail it on the doc or in a wiki or in Hibernate in Action, of course it is just a detail... and the source can be slightly modified.

but for the moment i'm spending time on the french translation of the reference doc ... Emmanuel will beat me if i'm too late :) so i add all this on my TODO list ;)


Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
delpouve wrote:
but for the moment i'm spending time on the french translation of the reference doc ... Emmanuel will beat me if i'm too late :) so i add all this on my TODO list ;)

Only if Christian kick my ass too ;-)

_________________
Emmanuel


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