Добавление перечисления как свойство класса в HBM

Альтернативный способ кодировать ответ Brettski, с которым я иначе соглашаюсь полностью, мог бы быть

With New FileSystemObject
    If .FileExists(yourFilePath) Then
        .DeleteFile yourFilepath
    End If
End With

Тот же эффект, но меньше (хорошо, ни один вообще) объявления переменной.

FileSystemObject является действительно полезным инструментом и определенно стоящий получения дружественным по отношению к. Кроме чего-либо еще, для текстового файла, пишущий это может на самом деле иногда быть быстрее, чем альтернатива прежней версии, которая может удивить несколько человек. (По моему опыту, по крайней мере, YMMV).

18
задан Avi Y 14 December 2009 в 07:12
поделиться

3 ответа

1) Easy solution: use Hibernate Annotations instead of XML-based mappings. Enum support is built-in:

@Entity
public class MyObject {
  @Enumerated(EnumType.STRING)
  @Column(name="EXAMPLE")
  private MyEnum myEnum;
}

2) If you can't use annotations, you can still use the EnumType they provide in XML-based mappings. You do need to have appropriate hibernate-annotations.jar in your classpath during deployment but there's no compile-time dependency:

<class name="a.b.c.myObject" table="OBJECT" >
  <property name="myEnum" column="EXAMPLE" type="org.hibernate.type.EnumType"/>
</class>
7
ответ дан 30 November 2019 в 07:44
поделиться

For reasons that remain obscure, the Hibernate developers insist on keeping the Hibernate core compatible with pre-Java5, and that means no enum support. When you try to persist an Enum field, it just serializes it, and you get binary data.

If you want to persist enums using an .hbm mapping configuration, you have to create and configure a custom UserType for each enum type you want to handle, which is tedious and irritating. The Hibernate documentation wiki has plenty of examples, many of which seem to contradict each other, and some of which even work.

If you use Hibernate annotations, though, you get full java5 support, including automatic handling of java5 enums. It's just a real shame that you have to do one or the other.

3
ответ дан 30 November 2019 в 07:44
поделиться

You need to use a UserType to persist that efficiently: https://www.hibernate.org/265.html

0
ответ дан 30 November 2019 в 07:44
поделиться
Другие вопросы по тегам:

Похожие вопросы: