简体   繁体   English

如何不使用 Hibernate UserTypes 的包信息文件?

[英]How to not use package-info files with Hibernate UserTypes?

Currently we register our user types in package-info.java files.目前我们在 package-info.java 文件中注册我们的用户类型。 The classes are specified using Strings which are difficult to maintain (a simple renaming will break the code).这些类是使用难以维护的字符串指定的(简单的重命名会破坏代码)。

Like this:像这样:

@TypeDefs(
  {
     @TypeDef(
           name = "lienPosition",
           typeClass = EnumUserType.class,
           parameters = {
              @Parameter(name = "enum", value = "com.package.level1.LienPosition")
           }
     )
  }

) )

Is there a way using Hibernate to register these UserTypes in a way that doesn't use Strings?有没有办法使用 Hibernate 以不使用字符串的方式注册这些用户类型?

Thanks, Alex谢谢,亚历克斯

I haven't used this myself, and I'm not sure it will cover your needs, but from the hibernate 3.6 docs , it looks like there is now a way to register types by a java call.我自己没有使用过它,我不确定它是否能满足您的需求,但从hibernate 3.6 文档看来,现在有一种方法可以通过 java 调用来注册类型。 This might be something you could hook into your startup if you're running a recent enough Hibernate.如果您正在运行足够新的 Hibernate,这可能是您可以在您的启动中挂钩的东西。 I don't believe this existed in 3.5 or earlier.我不相信这在 3.5 或更早版本中存在。

However, the discussion under this related bug indicates the changes made to the type system may also get in the way of your particular user types ( EnumUserType is referenced in the discussion), so it may be you need some other changes to deal with this.但是,此相关错误下的讨论表明对类型系统所做的更改也可能会妨碍您的特定用户类型(讨论中引用了EnumUserType ),因此您可能需要进行一些其他更改来处理此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM