I want to use something similar to org.springframework.transaction.annotation.Transactional
of Spring that sets up a Transaction only using only the Jersey API. Something similar to the code 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();
}
Is it possible?