3

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!

Alex Vayda
  • 6,154
  • 5
  • 34
  • 50

4 Answers4

7

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • That works, thanks! I'm using `AnnotationSessionFactoryBean`, so adding ``helped. – Alex Vayda Jun 04 '12 at 10:44
  • Using Hibernate 3, and NOT the `AnnotationSessionFactory`, I had to make the `configuration.addPackage('bla.bla.com')` call - that worked like a charm. Thanks! – demaniak Nov 20 '13 at 09:35
  • Can you please tell me how I can add this hibernate mapping entry with EntryManagerFactory ex: com.foo.bar.thepackage – Channa Feb 06 '15 at 03:03
2

For Hibernate 4, you have to add

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

to your Hibernate config file.

Niklas
  • 21
  • 1
2

If using JPA, using

<class>com.foo.bar.thepackage</class>
in the persistence.xml also should work.
Chris
  • 318
  • 2
  • 5
  • this worked for me, i am using persistence.xml. according to jboss docs class attribute in section 2.2.1. Packaging:https://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html_single/#architecture – rohith Jun 03 '16 at 15:46
2

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.

  • Fixed in version 3.2.2.RELEASE – Jon Freedman Jul 08 '16 at 10:56
  • For people having this issue, I recommend looking through the comments of [SPR-8589](https://jira.spring.io/browse/SPR-8589). While some issues were resolved in Spring 3.2.2, using it with JPA didn't really start working until Spring 4.1 or even later. Also look through the comments of linked ticket [SPR-10910](https://jira.spring.io/browse/SPR-10910). –  Jul 08 '16 at 11:49