简体   繁体   中英

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

Currently we register our user types in package-info.java files. 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?

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. This might be something you could hook into your startup if you're running a recent enough Hibernate. I don't believe this existed in 3.5 or earlier.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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