Amigo seu objeto está no estado detached, para exclusão, inserção e alteração ele precisar estar no estado persistent… O objeto precisa estar numa sessão valida. Veja o descritivo abaixo sobre o estado Detached e para os outros estados.
Detached - a detached instance is an object that has been persistent, but its Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. This feature enables a programming model for long running units of work that require user think-time. We call them application transactions, i.e. a unit of work from the point of view of the user.
Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application doesn’t hold a reference anymore. Use the Hibernate Session to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition).
Persistent - a persistent instance has a representation in the database and an identifier value. It might just have been saved or loaded, however, it is by definition in the scope of a Session. Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes. Developers don’t execute manual UPDATE statements, or DELETE statements when an object should be made transient.
um objeto Persistent eu poderia excluir,
o objeto Transient é quando eu, por exemplo, acabei de fazer "new Cliente()"
e o Detached é um que eu busquei do banco pelo entitymanager porém a seção “expirou” e ele não está mais associado com um objeto no banco, logo não posso exluir ele
se for isso, como eu faria esse objeto Detached virar Persistent para poder excluir ele?
eu teria que fazer o “entitymanager.find” no mesmo método que vou executar o remove para conseguir excluir?
ex:
Nenhuma deu certo… pois a primeira posso ate entender que e porque ele nao esta no escopo da sessao mais agora os outros depois de ter feito a busca ou depois de ter feito o merge ele ainda fala que ele nao consta la…
E toda vez que utilizo o em.consult(MyClass); ele informa false em todos os casos tbm…
Lembrando que o meu Bean e um Statefull… tentei o Statless e nada tbm
Minhas interfaces dao sao @Local
O que posso esta fazendo de errado? consigo fazer uma consulta, criar um novo e editar agora deletar num vai…
[quote=jrxxjr]Comigo a sintaxe :
"
Objeto classe = em.find(Objeto.class,1);
em.remove(em.merge(classe));
em.flush();
"
rolou.[/quote]
Isso tem que funcionar, evidentemente que o método find pode lançar uma exceção…