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:


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:

  1. i missed line in console output saying there constraint table , account cannot deleted.
  2. 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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -