Hibernate 注解 没有加@Column一样会在数据库创建这些字段

Hibernate 注解 没有加@Column一样会在数据库创建这些字段

如下一个注解类:

package com.hyy.hibernate.one_to_many.domain;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: HYY
 * Date: 13-11-28
 * Time: 下午8:50
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table
public class TypeToName {
    private Integer id;
    private String name;
    private Integer type;

    @Id
    @SequenceGenerator(name="increment")
    @GeneratedValue(strategy= GenerationType.AUTO, generator="increment")
    public Integer getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }
}

这个类只标明了他是一个注解类,并且主键是自增长的,然而其他的一些属性并没有配置注解,那么他一样会在数据库的表中存在,因为这些属性默认就有@Column注解。

因此如果没有添加注解,则hibernate会自动在属性前面添加@Column注解。

使用@Transient这个注解可以让其不成为数据库的字段。

原文地址:https://www.cnblogs.com/wuyou/p/3448441.html