Utilizando Hibernate com JBoss

0 respostas
temporarioruim

Pessoal,

Estou utilizando o Hibernate juntamente com o JBoss para persisitir os dados. Já configurei os arquivos e consegui realizar alguns testes. Porém estou com a seguinte dúvida: ao utilizar o hibernate com o jboss, seria possível delegar ao jboss o trabalho de salvar as os dados? Pois eu faço o controle da transação (commit ou rollback)…

public void doSomething() throws RemoteException {

Customer customer = new Customer();

customer.setName(Nome do customer);		

Session session = getHibernateSession();

Transaction tx = null;

try {

tx = session.beginTransaction();			

session.save(customer);

tx.commit();			

} catch (HibernateException e) {

if (tx != null) {

try {

tx.rollback();

} catch (HibernateException e1) {

throw new RuntimeException("Erro fazendo rollback: " + e.getMessage(), e);

}

}

throw new RuntimeException("Erro atualizando cliente: " + e.getMessage(), e);

} finally {

try {

session.close();

} catch (HibernateException e) {

throw new RuntimeException("Erro fechando sessao: " + e.getMessage(), e);

}

}

}

public static Session getHibernateSession(){

try

{

InitialContext ctx = new InitialContext();

SessionFactory jtaf = (SessionFactory)ctx.lookup(java:/hibernate/HibernateFactory);

return jtaf.openSession();

}

catch(NamingException e)

{

throw new RuntimeException("Erro obtendo sessao do Hibernate " + e.getMessage(), e);

} catch (HibernateException e) {

throw new RuntimeException("Erro obtendo sessao do Hibernate " + e.getMessage(), e);

}

}

Obrigado,

Rodrigo

Criado 20 de agosto de 2004
Respostas 0
Participantes 1