[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-4347) use property names defined in CompositeUserType as default column names

Frode Carlsen (JIRA) noreply at atlassian.com
Sat Oct 16 09:41:51 EDT 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4347?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Frode Carlsen updated HHH-4347:
-------------------------------

    Attachment: HH-4347-hibernate-testsuite.patch
                HH-4347-hibernate-core.patch

I've created a small patch for hibernate-core 3.6.0 to allow a CompositeUserType to define a default column mapping (using @Columns and @Column annotations), which will be concatenated with the name of the property to give unique names for an entity.  

I opted to allow the @Column annotations instead of the getPropertyNames(), as it is conceptually the same as using these on the property in the entity containing the type today, and it allows for defining other defaults as well (length, precision, nullable, etc).  
This means that when annotations are used, they are handled the same whether they are defined on the property (as today) or defined by default on the CompositeUserType, with the only difference being that in the latter case the name defined on the @Column annotation will be prefixed by the name of the property.  Also, column names are allowed to be different to the names used in queries, at the implementor's discretion.

The patch is backwards-compatible so if any CompositeUserType does not define any of these annotations then everything works the same as before.  Also, any @Columns/@Column annotations on a property in an entity will override the default defined.


> use property names defined in CompositeUserType as default column names
> -----------------------------------------------------------------------
>
>                 Key: HHH-4347
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4347
>             Project: Hibernate Core
>          Issue Type: New Feature
>          Components: annotations
>            Reporter: Michael Newcomb
>            Priority: Minor
>         Attachments: HH-4347-hibernate-core.patch, HH-4347-hibernate-testsuite.patch
>
>
> Consider:
> public class LongitudeLatitude
> {
>   protected double longitude;
>   protected double latitude;
> }
> public class LongitudeLatitudeCompositeUserType
>   implements CompositeUserType
> {
>   public String[] getPropertyNames()
>   {
>     return new String[] { "longitude", "latitude" };
>   }
>   public Type[] getPropertyTypes()
>   {
>     return new Type[] { Hibernate.DOUBLE, Hibernate.DOUBLE };
>   }
>   ...
> }
> @Entity
> public class Test
> {
>   @Basic(optional = false)
>   @Type(type = "foo.bar.LongitudeLatitudeCompositeUserType")
>   @Columns(columns = { @Column(name = "location_longitude"), @Column(name = "location_latitude") })
>   protected LongitudeLatitude location;
> }
> Why does the developer need to specify each column?
> I'd really rather let the CompositeUserType take care of that for me. Now, I have to tie the @Columns to the # of properties in my CompositeUserType AND the order in which they are defined? This seems to defeat the purpose of having a class (CompositeUserType) to tell Hibernate how to store it.
> Couldn't Hibernate prepend the property name 'location' and '_' to the front of each property name in the CompositeUserType?
> Perhaps (more than likely) I'm doing something wrong, but I get a failure if I do not specify the columns.
> Thanks,
> Michael

-- 
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