How would I do this without a DAO:
Code:
public class Currencies {
private Collection<Currency> currencies;
// getter and setter
}
@Entity @Table(name="currency_data")
public class Currency {
@Id @Column private Integer number;
@Column private String name;
// getters and setters
}
Is there a setup, using which hibernate can load all currencies on: "new Currencies().getCurrencies()".
A JPA solution would be good to have, but not a requirement.
I have this currently working as (using DAO):
Code:
public Currencies loadTable() {
final EntityManager em = PersistenceHelper.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
try {
Collection<Currency> cs = em.createQuery("from Currency").getResultList();
return new Currencies(cs);
}
finally {
tx.rollback(); // read-only
}
}
Hibernate version: 3.2
Mapping documents: annotations 3.3.1 / hibernate entity manager 3.3.2
Requirement:
We use Coherence caching solution. This data needs to be in cache as a single object (Collection of all currencies).
I am trying to setup cache configuration to use JPA so that whenever it needs something from the database, cache can itself use JPA to get it.
Any help / pointers would be greatly appreciated.
Ajay