Hbm2ddl ignores @Column annotation?

Why does hbm2ddl ignore @Column annotation?

This is my class: -

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "BASETEMPLATE") public class BaseTemplate implements IBaseTemplate { private Integer id; @Column(name="TEMPLATENAME") private String templateName; @Column(name="BASETEMPLATEID") private Integer baseTemplateId; @Id @GeneratedValue @Column(name = "TEMPLATEID") @Override /** {@inheritDoc} */ public Integer getId() { return id; } ... } 

and hbm2dll generates this table (sqlserver)

 dbo.BASETEMPLATE ( TEMPLATEID int templateName varchar(255) baseTemplateId int ) 

dialect - org.hibernate.dialect.SQLServerDialect Is it strange that the primary key is always generated correctly?

+4
source share
2 answers

When you post annotations on getters, Hibernate uses a property access strategy; when you place them in fields, Hibernate uses a field access strategy. However, you should not mix these strategies in the same object (or, more precisely, in the same inheritance hierarchy), unless you use @Access for small-scale control of the access strategy.

By default, Hibernate expects annotations to fit in the same way as @Id , so in your case, it expects @Id annotations.

+5
source

I do not know why @Column in the field is ignored by hbm2ddl, but I found that if you annotate the getter, it sets the column name in the table correctly.

0
source

All Articles