MySQL的枚举与休眠

MySQL的枚举与休眠

本文介绍了MySQL的枚举与休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用枚举的数据库表。这已经与hibernate(使用XML)一起工作了,我试图将它转换为注释,因为这是仍然使用xml表示法的最后一部分之一。

I have a database table using an enum. This is already working with hibernate (using XML), and I'm trying to convert it to annotations as this is one of the last pieces to still be using xml notation.

列定义:

The column definition:

enum('Active','Pending','Cancelled','Suspend')

以下工作:

The following works:

<property
    name="status"
    column="STATUS"
    type="string"
    not-null="true" />

这不起作用:

This does not work:

@Column(name = "status")
public String status;

注释样式在启动时会导致以下异常:
org.hibernate.HibernateException :UserDTO中的列的类型错误以显示列状态。发现:enum,expected:varchar(255)

The annotation-style leads to the following exception upon startup:org.hibernate.HibernateException: Wrong column type in UserDTO for column status. Found: enum, expected: varchar(255)

有没有什么办法强迫它接受一个String,因为它使用XML符号?

Is there any way for me to force this to accept a String as it did using the XML notation?

推荐答案

我想通了。它应该是:

I figured it out. It should be:

@Column(name="status", columnDefinition="enum('Active','Pending','Cancelled','Suspend')")
public String status;

这篇关于MySQL的枚举与休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:51