Showing posts with label hibernate. Show all posts
Showing posts with label hibernate. Show all posts

Tuesday, December 23, 2008

Hibernate emits empty DDL file


This is the second time this has bitten me: I want to use Hibernate with standard JPA to persist my entities. And I want my Entities autodetected, as Hibernate is capable of, even outside of a JEE container. So in my persistence.xml I have this bit of code:
      <property name="hibernate.archive.autodetection" value="class,hbm"/>
But, I do not compile this persistence.xml into my .jar file, instead I just make it part of my classpath for my unit tests, thinking this will make things more flexible. And of course, this doesn’t work. The autodetection only works if the persistence.xml is located in the META-INF section of the jarfile that contains the Entities to be detected. See my post in the Hibernate forum.

Thursday, December 11, 2008

Hibernate JPA annotations work only on get method, not set


I have a project where I'm using Hibernate with JPA annotations. I got stuck where the annotations to one of my attributes wouldn't stick, but I finally figured it out:


You have to annotate either the member (in which case all attributes must be annotated via member), or the get method for your attribute. You can't annotate the set method.