2011-07-11 131 views
1

*我在实体中获得以下内容。休眠不会创建表

@Entity("User") 
public class User implements java.io.Serializable { 
    @ElementCollection(fetch=FetchType.EAGER) 
    @CollectionTable(name="FrameworkUser_Properties") 
    public Map<String, String> getProperties() { 
     return properties; 
    } 
    public void setProperties(Map<String, String> properties) { 
     this.properties = properties; 
    } 
} 

我得到以下错误

Unsuccessful: create table FrameworkUser_Properties (User_id int not null, properties varchar(255) null, properties_KEY varchar(255) null, primary key (User_id, properties_KEY)) 

任何人有任何想法,我应该怎么做,是properties_KEY没有空呢? 我使用Hibernate休眠3.6.5.Final,MSSQL

// Trind

+0

是如何故在声明定义properties_KEY问题创建表语句为null或者是为什么无法创建表的问题? – padis

+0

我希望能够创建表格。肯·陈为我解决了这个问题。 – Trind

回答

1

似乎要映射的收藏价值键入使用散列映射。您必须指定使用@MapKeyColumn

例如,你可以尝试一下,看是否可以解决问题HashMap中的键列:

@ElementCollection(fetch=FetchType.EAGER) 
@CollectionTable(name="FrameworkUser_Properties") 
@MapKeyColumn 
public Map<String, String> getProperties() { 
      return properties; 
} 
+0

感谢这工作完美:) – Trind

1

我相信你可以做这样的事情:

@CollectionTable(
     name="FrameworkUser_Properties", 
     [email protected](name="OWNER_ID", nullable = false) 
)