[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4479) We should be able to implement Joins using formulas with Annotations

Sharath Reddy (JIRA) noreply at atlassian.com
Mon Oct 12 00:49:41 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34148#action_34148 ] 

Sharath Reddy commented on HHH-4479:
------------------------------------

Hi Paul,

I think this discussion has segued into 2 different issues:

1. Your comment: 'Because Joins are name-based, not positional-based' 

Not necessarily true. Emmanuel told me that 'referencedColumnName' is mandatory as per the JPA spec. HOWEVER, because of legacy reasons, IF a join refers to a composite primary key, AND the foreign key columns are specified in the same order as the corresponding columns of the primary key, then Hibernate does not require this attribute to be specified (As it is implicit). 

Or to put it in another way, if the 'referencedColumnName' attribute is not specified, Hibernate assumes it is referring to the primary key of the referenced entity. 

We want to preserve this going forward. 

2. Forgetting about formulas for the moment, from a purely practical stand-point, the way the AnnotationBinder currently parses the annotated classes, it REQUIRES the @JoinColumns annotation if a join involves multiple columns. So the following would not work: 

@ManyToOne
@JoinColumn(name="order_nbr", referencedColumnName="order_nbr")
@JoinColumn(name="is_default", referencedColumnName="is_default")
public Menu getOrder() {
    return order;
} 

The parser would arbitarily select either one of the @JoinColumn annotations, or may be throw an exception (I have to check). If you want to join on multiple columns, you HAVE to use @JoinColumns. 

@JoinColumns{ @JoinColumn(..), @JoinColumn(..) }

So it is probably logically consistent that if you have a join consisting of a join column AND a formula, you use some kind of wrapper annotation. 

However, I do see your point. @JoinColumnsOrFormulas does not sound...elegant. 

Let me discuss this again with Emmanual and get back to you. 















> We should be able to implement Joins using formulas with Annotations 
> ---------------------------------------------------------------------
>
>                 Key: HHH-4479
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4479
>             Project: Hibernate Core
>          Issue Type: New Feature
>          Components: annotations
>            Reporter: Sharath Reddy
>            Assignee: Sharath Reddy
>            Priority: Minor
>             Fix For: 3.5
>
>         Attachments: HHH-4479.patch, HHH-4479second.patch
>
>
> This article published on the O'Reilly web site - http://onjava.com/pub/a/onjava/2005/08/03/hibernate.html?page=3 - describes how to implement joins with formulas, using the hbm xml files. We should be able to do the same with annotations: 
> <hibernate-mapping>
>   <class name="Company" table="Company">
>     <id name="id" />
>     <many-to-one 
>       name="defaultContactPerson" 
>       property-ref="defaultContactPerson">
>         <column name="id"/>
>         <formula>1</formula>
>         </many-to-one>
>   </class>
>   <class name="Person" >
>     <id name="id" />
>     <properties name="defaultContactPerson">
>         <property name="companyID" />
>         <property name="defaultFlag" />
>     </properties>
>   </class>
> </hibernate-mapping>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list