如何在游戏中存储具有固定值的枚举
我正在尝试将 grails-project 转换为 playframework。在 Grails 中,您可以定义一个 id,以便将 id 存储在数据库中(请参阅 发行说明)。 我看到一个类似问题,但没有可接受的解决方案。如果我更改类型,CRUD 模块就会出现问题,因为应该显示枚举的信息会丢失。
所以我想知道是否存在一个基于 Hibernate 的很好的 play 解决方案。也许是通过破解 JPAPlugin 来实现的?
[更新 1] 我开始尝试使用 @type
-annotation 的第二个解决方案。不幸的是,这在 hibernate 3.6 中被破坏了(play 1.2.2 使用它)。 TypeFactory.basic()
不是 可用了。但根据文档我找不到解决方法。
[更新 2] 有一个用于休眠的解决方案 3.6.1,但是在每次使用枚举时都定义类型确实很笨拙。
@Type(type="hibernatehelper.GenericEnumUserType",
parameters= {
@Parameter(
name = "enumClass",
value = "models.Geschlecht"),
})
public Geschlecht geschlecht = Geschlecht.WEIBLICH;
I'm trying to convert a grails-project to the playframework. In Grails you can define an id so the the id will be stored in the database (see Enhanced Enum Support in the release notes).
I saw a similar question, but with no acceptable solution. If I change the type the CRUD-module get a problem, because the information that a Enum should be shown is lost.
So I wonder if there exists a nice solution with play, which based on Hibernate. Perhaps with hacking the JPAPlugin?
[Update 1] I started to try the second solution with @type
-annotation. Unfortunately this become broken with hibernate 3.6 (which is used by play 1.2.2). TypeFactory.basic()
is not available any more. But following the documentation I can't find a work around.
[Update 2] There was a solution for hibernate 3.6.1, but it's really clumsy to define the type at each usage of enum.
@Type(type="hibernatehelper.GenericEnumUserType",
parameters= {
@Parameter(
name = "enumClass",
value = "models.Geschlecht"),
})
public Geschlecht geschlecht = Geschlecht.WEIBLICH;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定它是否真的有效,但一种可能的解决方案可能如下:
编写了一个通用类型映射器:
编写了一个增强器,它查找来自 Type
Enum
的每个属性,并查看该类型是否具有静态方法 parseId。比 使用 javaassist 添加以下注释:但我不确定这对于解决这样的问题是否没有太大的魔力。也许有人可以给我建议。
Not sure if it's really work, but one possible solution could be the following:
Wrote a generic type mapper:
Wrote an Enhancer which look for every attribute which is from Type
Enum
and look if this type has a static-method parseId. than add the following annotation with javaassist:But I'm unsure if this not to much magic for such a problem. Perhaps someone can give me an advice.