Hi Michael,
Yes, it is supposed to work.
Have a look at hibernate annotations implementation.
This implements the javax.persistence api for annotations plus some extra things.
You might also need a HibernateUtil class.
Have a look at the examples bundled with the annotations package.
Code:
public class HibernateUtil {
private static Logger log = Logger.getLogger(HibernateUtil.class);
private static AnnotationConfiguration cfg;
private static final SessionFactory sessionFactory;
static {
try {
cfg = new AnnotationConfiguration();
Class[] classes = getMappings();
for ( int i = 0; i < classes.length ; i++ ) {
cfg.addAnnotatedClass( classes[i] );
}
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable ex) {
log.error("error initializing Hibernate sessionFactory",ex);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException {
return sessionFactory.openSession();
}
protected static Class[] getMappings() {
return new Class[]{
Text.class,
Sentence.class,
};
}
}