I have an EntityManager object maintained by the Spring framework and I inject it in whatever DAO class I want using the @PersistenceContext annotation like this..
@PersistenceContext(unitName="entityManager")
private EntityManager em;
I use those DAO classes to save in the database something like this..
class MyClass
{
@Resource(name="myDao")
private MyDao dao;
@Resource(name="myAnotherDao")
private MyAnotherDao anotherDao;
public void save(String s1,String s2)
{
try
{
MyEntity m=new MyEntity();
m.setName(s1);
// .. and so on ..
XYZ x=new XYZ();
x.setDEF(s2);
anotherDao.save(x);
m.setXYZ(x);
// .. some other stuff .. //
dao.save