-->
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.  [ 1 post ] 
Author Message
 Post subject: AttributeOverride breaks key of embedded map in hbm2ddl
PostPosted: Thu Jan 27, 2011 10:58 am 
Newbie

Joined: Thu Dec 14, 2006 6:42 am
Posts: 15
(I posted this in the wrong forum here: viewtopic.php?f=1&t=1009247)

I have an entity that embeds an object which contains a map.
If I change the column name, the map key of the embedded object disappears in the schema generated by the hbm2ddl tool.
Example:

The Product entity
Code:
package com.demo.entity;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Product {
   private Long id;
   private LocalString description;

   @Id @GeneratedValue
   public Long getId() {
      return id;
   }

   @Embedded
   public LocalString getDescription() {
      return description;
   }
}

The LocalString component
Code:
package com.demo.entity;

import java.util.Locale;
import java.util.Map;

import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;

@Embeddable
public class LocalString {
    private Map<Locale, String> localStrings;

    @ElementCollection
    public Map<Locale, String> getLocalStrings() {
       return localStrings;
    }
}


The hibernate configuration
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <property name="connection.datasource">java:/comp/env/jdbc/dbprod</property>

      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="id.new_generator_mappings">true</property>

      <mapping class="com.demo.entity.Product" />
   </session-factory>
</hibernate-configuration>


The generated schema (good)
Code:
create table Product (id bigint not null, primary key (id));
create table Product_localStrings (Product_id bigint not null, localStrings varchar(255), localStrings_KEY varchar(255), primary key (Product_id, localStrings_KEY));
alter table Product_localStrings add index FKA32FCA07406721A1 (Product_id), add constraint FKA32FCA07406721A1 foreign key (Product_id) references Product (id);
create table hibernate_sequence ( next_val bigint );
insert into hibernate_sequence values ( 1 );


Now I change the column name:
Code:
   @Embedded
   @AttributeOverrides( {
      @AttributeOverride(name="localStrings", column = @Column(name="desc") )
   })
   public LocalString getDescription() {
      return description;
   }

The generated schema becomes:
Code:
create table Product (id bigint not null, primary key (id));
create table Product_localStrings (Product_id bigint not null, desc varchar(255), primary key (Product_id, desc));
alter table Product_localStrings add index FKA32FCA07406721A1 (Product_id), add constraint FKA32FCA07406721A1 foreign key (Product_id) references Product (id);

where localStrings_KEY has disappeared.

How do I fix this?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.