Annotation Weirdness
http://stackoverflow.com/questions/305880/hibernate-annotation-placement-questionFor 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.
Interceptors
http://stackoverflow.com/questions/11428410/hibernate-4-0-0final-where-is-the-sessionfactory-opensessioninterceptor-interceIf you wanted a per-session interceptor you need to do
Session session = sesssionfactory.withOptions()
.interceptor(new Interceptor())
.openSession();
Event Listeners
To create and use a listener you must first create a listener:
public class EntityListener
{
@PrePersist
@PostPersist
@PreUpdate
@PostUpdate
@PreRemove
@PostLoad
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.