hbm2ddl忽略@Column注释? [英] hbm2ddl ignores @Column annotation?

查看:105
本文介绍了hbm2ddl忽略@Column注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hbm2ddl为什么会忽略@Column注释?

Why would hbm2ddl ignore the @Column annotation ?

这是我的课程:-

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

和hbm2dll生成此(sqlserver)表

and hbm2dll generates this (sqlserver) table

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

方言是org.hibernate.dialect.SQLServerDialect 奇怪的是,主键总是正确创建的吗?

dialect is org.hibernate.dialect.SQLServerDialect Strangely the primary key is always created correctly ?

推荐答案

将注释放置在getter上时,Hibernate使用属性访问策略,将注释放置在字段上时,Hibernate使用字段访问策略.但是,除非您使用

When you place annotations on getters, Hibernate uses property access strategy, when you place them on fields, Hibernate uses field access strategy. However, you should not mix these strategies in the same entity (or, more precisely, in the same inheritance hierarchy), unless you use @Access for fine-grained control over access strategy.

默认情况下,Hibernate希望注释的放置方式与@Id相同,因此,在您的情况下,它希望在getter上放置注释.

By default Hibernate expects annotations to be placed in the same way as @Id, therefore in your case it expects annotations on getters.

这篇关于hbm2ddl忽略@Column注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆