2
I want to use something similar to org.springframework.transaction.annotation.Transactional
Spring that configures a Transaction only using only the Jersey API. Something similar to the code that follows below:
@Resource
private SessionFactory factory;
private Class<E> entity;
private String tableName;
public DataProvider(Class e) {
this.entity = e;
this.tableName = entity.getAnnotation(Table.class).name();
}
@Transactional(readOnly = true)
public E get(final Long ID) {
return (E)factory.getCurrentSession().get(entity, ID);
}
@Transactional(readOnly = true)
public List<E> getAll() {
Session s = factory.getCurrentSession();
return s.createQuery("FROM " + tableName ).list();
}
It is possible?
Only to complete, since Java EE 7 it is already possible to use the annotation
Transactional
directly in CDI-administered Beans (i.e., on application servers such as Wildfly and Glassfish 4 simply note the bean, you will not need to implement interceptors). In containers Servlet (Tomcat, Jersey, etc.) you need to configure the implementations at hand (e. g , Weld + Hibernate + Atomikos)– Anthony Accioly