hibernate won't create table
*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)
)
精彩评论