开发者

hibernate won't create table

开发者 https://www.devze.com 2023-03-19 02:32 出处:网络
*I got the following in an entity. @Entity(\"User\") public class User implements java.io.Serializable {

*I got the following in an entity.

@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;
    }
}

i get the following error

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

Anyone got any idea how i should do so is properties_KEY is not null instead? I use Hi开发者_运维技巧bernate Hibernate 3.6.5.Final, MSSQL

//Trind


It seems that you are mapping the collection of the value type using the hashmap . You have to specify the key column of the hashmap using @MapKeyColumn

For example , you can try it to see if the problem can be solved:

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


I belive you can do something like this:

 @CollectionTable(
        name="FrameworkUser_Properties",
        joinColumns=@JoinColumn(name="OWNER_ID", nullable = false)
  )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号