I'm trying to use Hibernate @TypeDef annotation on a package level, exactly as it is described in the Hibernate documentation. I'm using Hibernate 3.6 and Spring 3.0.7. The code compiles and the package-info.class is in the classpath, but still it is not seen by the Hibernate.

If I put @TypeDef on the class level, it's working, but not if I put in the package-info. I tried to google but couldn't find anything helpful.

Thank you!

有帮助吗?

解决方案

You probably need to add a

<resource package="com.foo.bar.thepackage"/>

to your Hibernate config file, or to call configuration.addPackage("com.foo.bar.thepackage").

其他提示

For Hibernate 4, you have to add

<mapping package="com.foo.bar.thepackage">

to your Hibernate config file.

If using JPA, using

<class>com.foo.bar.thepackage</class>
in the persistence.xml also should work.

I believe this is due to a bug in Spring, where it doesn't scan the annotations in package-info, but only those on classes annotated with @Entity, @Embeddable, or @MappedSuperclass. See https://jira.springsource.org/browse/SPR-8589.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top