0

在我的 Java 应用程序中创建具有一个字段的值对象(Java Bean)

@Entity
@Table(name="EC_TIMETABLE")
    public class TimetableVO
{
----//@id and some other column and variables
----

private List<WeekdayType> repeatDays;//Their is No column in Database
------
------//setter and getter method
}

听说 WeekdayType 是 Enum 类

public static enum WeekdayType {
    MONDAY(Calendar.MONDAY), TUESDAY(Calendar.TUESDAY), WEDNESDAY(
            Calendar.WEDNESDAY), THURSDAY(Calendar.THURSDAY), FRIDAY(
            Calendar.FRIDAY), SATURDAY(Calendar.SATURDAY), SUNDAY(
            Calendar.SUNDAY);

    private int day;

    private WeekdayType(int day) {
        this.day = day;
    }

我正在使用 TimetableVO getRepeatedDays() 另一个类。

当我启动服务器时出现错误

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: EC_TIMETABLE, for columns: [org.hibernate.mapping.Column(repeatDays)]

他们在数据库或语法问题中需要的任何列也是如此.....提前谢谢..

4

3 回答 3

1

不,如果您不想,您不需要在数据库中为该字段提供一列。

如果您不想使其持久化,可以通过 @Transient 注释将其标记为瞬态。

@Transient
private List<WeekdayType> repeatDays;
于 2012-12-10T09:03:14.043 回答
0

JPA's @Transient annotation is used to indicate that a field is not to be persisted in the database, i.e. their semantics are different.

Now the solution is ...

@Transient
private List<WeekdayType> repeatDays;
于 2012-12-10T09:19:48.990 回答
0

将集合标记为瞬态将指示 Hibernate 这不是持久项。我认为这样事情更符合您的要求。

于 2012-12-10T09:06:40.157 回答