【问题标题】:Hibernate, class property that is not binded to the tableHibernate,未绑定到表的类属性
【发布时间】:2012-12-11 02:52:00
【问题描述】:

我有这样的问题:我在 Test 类中有一个属性,它不应该映射到表的列(我在加载我的 Test 对象后使用它来确定是否应该删除 Test 对象)。在我的例子中,这个属性是布尔删除:

@Entity
@Table(name = "[NewMVC].[dbo].[Tests]")
public class Test {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id; 

    @Column(name = "testQuestion")
    private String testQuestion;

    @Column(name = "optionOne")
    private String optionOne;

    @Column(name = "optionTwo")
    private String optionTwo;

    @Column(name = "optionThree")
    private String optionThree;

    @Column(name = "subjectType")
    private int subjectType;

    @Column(name = "correctOptionNumber")
    private int correctOptionNumber; 

    private boolean delete = false;
....

我应该如何告诉 hibernate 我的属性删除没有映射到列?

【问题讨论】:

    标签: spring hibernate spring-mvc orm


    【解决方案1】:

    你可以用@Transient注解来注解它:

    @Transient
    private boolean delete = false;
    

    这告诉 Hibernate 跳过这个属性而不是生成列。

    【讨论】:

      【解决方案2】:

      使用@Transient 注解:

      @Transient
      private boolean delete;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-08
        • 2020-04-19
        • 2021-03-11
        • 2017-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多