views:

463

answers:

1

Hi, Using auto update (hibernate.hbm2ddl.auto=update) I have a entity which is supppose to create two tables: myentity and myentityconfigurationProperties. This works fine in Mysql 5, but in SQL server 2005 it doesnt create the property table.

Anyone knows anything about this? I havn't tried creating the table myself, I'd like to avoid that, so I dont know if it is working at all in SQL server, but it works fine in Mysql.

This is the entity (simplified):

@Entity
public class MyEntity  {
    Map<String, String> configurations = new HashMap<String, String>();
    long id = -1;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @CollectionOfElements(fetch = FetchType.EAGER)
    @JoinTable(
            name = "myentityconfigurationProperties",
            joinColumns = @JoinColumn(name = "id")
    )
    @org.hibernate.annotations.MapKey(
            columns = @Column(name = "propertyKey")
    )
    @Column(name = "propertyValue", nullable = false)
    @Cascade(value = org.hibernate.annotations.CascadeType.ALL)
    public Map<String, String> getConfigurations() {
        return configurations;
    }

    public void setConfigurations(Map<String, String> configurations) {
        this.configurations = configurations;
    }

}
A: 

The error was that SQL server doesn't allow null keys, which MySQL obviously handles. So the fix is:

@org.hibernate.annotations.MapKey(
        columns = @Column(name = "propertyKey", nullable = false)
Tomas