You are viewing...

Because Hibernate 4.1 docs are pretty annoying

Updated on February 13, 2013 at the 09th hour
Posted under:

DISCLAIMER: Expressed views on this blog are my own.

Annotation Weirdness

For a weird reason, it doesn't like @Id annotation on a field. It fails to get the type when I place it on the field. Even if it gets the type, the error cascades to joins and something will fail down there. :/ Still learning to use JPA Annotations for Hibernate.


If you wanted a per-session interceptor you need to do
Session session = sesssionfactory.withOptions()
.interceptor(new Interceptor())

Event Listeners

To create and use a listener you must first create a listener:
public class EntityListener

public void onEvent(Object thing)
//do thing

then attach the listener to the entity with this annotation: @EntityListeners({EntityListener.class}). Furthermore, you must use an EntityManager either generated from from E3jbConfiguration (deprecated) or Persistence.createEntityManagerFactory(). The former will use a hibernate.cfg.xml (go figure....) and the latter will need persistence.xml (in src/META-INF/ dir... just create it) because it is the JPA one.

You can also use those annotations in your entity class, but they do not require an argument.
You just read "Because Hibernate 4.1 docs are pretty annoying". Please share if you liked it!
You can read more recent posts here.