1

I'm doing a migration from Session to JPA use, so I have most of the Mapping definitions in hbm.xml files. For this to work I create a persistence.xml file and reference my hibernate.cfg.xml from there . I also refactor my HibernateUtil and replace the use of SessionFactory and Session by EntityManagerFactory and EntityManager. Everything looks fine, so I start running test to see if I could build my EntityManagerFactory. Doing this I found that all my hbm.xml files are processing ok, but hibernate could not determine the type for User Types. How this User Types definition use to work with old hibernate.cfg.xml and SessionFactory, well I have a tag typedef on any hbm.xml file where I defined this like:

<typedef class="com.mycompany.myproduct.hibernate.MyUserType" name="my_type"/>

And then I used in multiple hbm.xml files like this:

<property name="code" column="cod" type="my_type"/>

So I have it defined once in some hbm.xml file but I could used on any other hbm.xml file only referenced by the alias. Now with JPA EntityManagerFactory it doesn't work in the same way, I mean I need to define the typedef tag on each hbm.xml file I want to use it or I will received an exception:

Caused by: org.hibernate.MappingException: Could not determine type for: my_type, at table: mytable, for columns .....

Question are:

  • Is this the expected behavior with EntityManagerFactory, or maybe I'm doing something wrong?
  • Is there any way I could define a typedef only once and used everywhere?

Thanks for your comments. Daniel

4

0 回答 0