java - Play JPA - Error: Removing a detached instance -
i'm using play framework 2.4 , got error:
[illegalargumentexception: removing detached instance models.account#8] in: (...)\models\account.java jpa.em().remove(this)
my code looks this:
- profilecontroller: http://pastebin.com/embed_iframe.php?i=257pthm4
- account: http://pastebin.com/embed_iframe.php?i=wn1wchni
i tried (as suggested many other answers similar questions):
jpa.em.remove(jpa.em().merge(this);
or
jpa.em().remove(account.findbyid(this.id));
or adding @transactional
delete() function.
but both result in
rollbackexception: error while committing transaction
.
update - solution:
it mixture of 2 problems:
- i missed line in console output saying there constraint table , account cannot deleted.
the account instance returned
component.currentaccount()
detached instance , fixed with:account current = jpa.em().merge(component.currentaccount())
only guess: object tree must in sync database structure.
if remove jpa controlled bean, must remove collections, possibly part of.
so, if account part of list of accounts in company or listed in accessgroup, must remove elements before account can deleted. valid if other objects loaded jpa session.
the initial error have posted should have been resolved explicitely reloading object or reconnecting object persistent state has been proposed others.
if guess right, , use hibernate, commit failure accompanied deleted object re-saved cascade
.
Comments
Post a Comment