[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-5136) map-key-column is broken

Hardy Ferentschik (JIRA) noreply at atlassian.com
Fri Dec 17 04:53:14 EST 2010


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

Hardy Ferentschik resolved HHH-5136.
------------------------------------

       Resolution: Fixed
    Fix Version/s: 4.0.0.Alpha1
                   3.6.1

> map-key-column is broken
> ------------------------
>
>                 Key: HHH-5136
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5136
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.5.1
>         Environment: Hibernate 3.5.1, PostgreSQL 8.4.3
>            Reporter: Harald Wellmann
>            Priority: Critical
>             Fix For: 3.6.1, 4.0.0.Alpha1
>
>
> I have an entity with a Map<String, Embeddable> with unexpected behaviour. The problem is that annotation mappings and the equivalent XML mappings yield different results. (For brevity, I'm leaving out the getters and setters and the SQL constraints in the following examples.)
> Here is my Embeddable:
> {code:java}
> @Embeddable
> public class LocalizedString
> {
>     private String language;
>     private String text;
> }
> {code}
> And this is the containing entity:
> {code:java}
> @Entity
> public class Amenity 
> {
>     @Id
>     @Column(name = "amenity_id")
>     @GeneratedValue
>     private long id;
>     @ElementCollection
>     @CollectionTable(name = "amenity_name", joinColumns = @JoinColumn(name = "amenity_id"))
>     @MapKeyColumn(name = "language_map_key")
>     private Map<String, LocalizedString> names = new HashMap<String, LocalizedString>();
> }
> {code}
> Hibernate generates the following collection table:
> {code:sql}
> CREATE TABLE amenity_name
> (
>   amenity_id bigint NOT NULL,
>   "language" character varying(255),
>   "text" character varying(255),
>   language_map_key character varying(255) NOT NULL
> )
> {code}
> Now when replacing the annotations by the following XML mapping
> {code:xml}
> <?xml version="1.0" encoding="UTF-8"?>
> <entity-mappings version="2.0"
> 	xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
> 	<entity class="Amenity">
> 		<attributes>
> 			<id name="id">
> 				<column name="amenity_id"/>
> 				<generated-value />				
> 			</id>
> 			<element-collection name="names">
> 				<map-key-column name="language_map_key" />
> 				<collection-table name="amenity_name">				
> 					<join-column name="amenity_id" referenced-column-name="amenity_id"/>
> 				</collection-table>
> 			</element-collection>
> 		</attributes>
> 	</entity>
> 	<embeddable class="LocalizedString">
> 	  <attributes>
> 	    <basic name="language"></basic>
> 	    <basic name="text"></basic>
> 	  </attributes>
> 	</embeddable>
> </entity-mappings>
> {code}
> the generated SQL looks like this:
> {code:sql}
> CREATE TABLE amenity_names
> (
>   amenity_amenity_id bigint NOT NULL,
>   "language" character varying(255),
>   "text" character varying(255),
>   names_key character varying(255) NOT NULL
> )
> {code}
> It seems that the map-key-column and collection-table settings are simply ignored.
> Another question: The column language_map_key is actually redundant, I would like to use the language column as map key instead. The JPA 2.0 spec is a bit vague on this case. When the map value is an entity, @MapKey can be used to select a property of the entity value as map key, but it is not clear to me whether the spec supports supressing the separate key column when the map value is an embeddable.
> I tried using @MapKeyColumn(name="language"), but then Hibernate complained about a duplicate column.
> Eclipselink (the version contained in Glassfish v3) accepts this usage and suppresses the duplicate column, i.e. the join table has the form
> {code:sql}
> CREATE TABLE amenity_name
> (
>   amenity_id bigint NOT NULL,
>   "language" character varying(255),
>   "text" character varying(255)
> )
> {code}

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