não sei o que estou fazendo de errado estou tentando validar umas rotina via JUNIT não estou usando nenhum servidor de aplicação
estou rodando stand-alone
E me da o erro quando executo o codigo abaixo Erro :0::Can not find by ID
não acha o codigo pelo metodo find mas existe no banco quando rodo só esse metodo ele acha ???
Começou isso depois que inserir o metodo Close em todos os metodos …
MAs uma duvida quando uso find e depois um merge da erro EntiTyManager is close …não posso
fazer um select e fechar o EntityManager ???
É errado usado close em find(select) a sessão bão vai ficar aberta senão fechar ???
Existe diferença quando usa JPA via WEB e via JSE ???
se alguém puder me ajudar ???
public class TestImsCompanyDaoI {
@Test
public final void testInsertCompanycomUsercomAddress() throws DaoException {
try{
dao = new UserDao();
user = new User();
user.setName("New Company ");
dao.persist(user);
}
}catch(Exception e){
System.out.println("Erro = " + e);
}finally{
}
}
@Test
public final void testMerge() {
UserDao dao = new UserDao();
try{
User us =dao.find(4L);
us.setName("Company New +++");
dao.merge(us);
} catch (Exception e) {
System.out.println("Erro testUpdate() ="+e);
}
}
}
public AbstractBaseDao() {
bMANAGER = DATAS.getInstance();
System.out.println("Conteudo Construtor() AbstractBaseDao = "+bMANAGER);
}
public void persist(T t) throws DaoException {
try {
bMANAGER.BeginTransaction();
bMANAGER.getManager().persist(t);
bMANAGER.CommitTransaction();
} catch(Exception e) {
throw new DaoException(getErrorCode(METHOD_PERSIST), "Can not insert", e);
}finally{
bMANAGER.Close();
}
}
-----
public void merge(T t) throws DaoException {
try {
bMANAGER.BeginTransaction();
bMANAGER.getManager().merge(t);
bMANAGER.CommitTransaction();
} catch(Exception e) {
throw new DaoException(getErrorCode(METHOD_MERGE), "Can not update", e);
}finally{
bMANAGER.Close();
}
}
---
public T find(T entity) throws DaoException {
T t = null;
try {
t = bMANAGER.getManager().find(domainClass, entity);
return t;
} catch(Exception e) {
throw new DaoException(getErrorCode(METHOD_FIND_BY_CLASS), "Can not find by Class", e);
}finally{
bMANAGER.Close();
}
}