Why would Hibernate ignore package-info.java?

5.3k views Asked by At

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!

4

There are 4 answers

3
JB Nizet On BEST ANSWER

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").

1
Chris On

If using JPA, using

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

0
Niklas On

For Hibernate 4, you have to add

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

to your Hibernate config file.

2
AudioBubble On

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.