hibernate - Envers RevisionEntity can not be saved with Metadata -


i have application written in play framework hibernate. want add versioning envers library.

i have user class.

@entity @audited(withmodifiedflag=true) public class user  

a controller change things user.

@transactional public static result updateaccountstates(long userid) {     user user = jpa.em().find(user.class, userid);     integer prevstatus = user.status;     form<accountstateform> form = form.form(accountstateform.class).bindfromrequest();     form.get().applyto(user);     return redirect(routes.customers.account(userid)); } 

i want add metadata changed users data.

@entity @revisionentity(userrevisionlistener.class) public class userrevisionentity extends defaultrevisionentity {     @manytoone     public staff staff; }  public class userrevisionlistener implements revisionlistener {     @override     public void newrevision(object revisionentity) {          userrevisionentity userentity = (userrevisionentity) revisionentity;         userentity = securityutils.getstaff(ctx());     } } 

every time user changes record witch staff member changed it.

i have added userrevisionentity model persistence.xml:

<class>models.userrevisionentity</class> 

when change user status get:

[error] o.h.e.j.s.sqlexceptionhelper - cannot add or update child row: foreign key constraint fails (`creditgate24`.`user_aud`, constraint `fk_97pph94d4cb7qah5aygmmll2y` foreign key (`rev`) references `revinfo` (`rev`)) [error] play - cannot invoke action, got error: java.lang.runtimeexception: javax.persistence.rollbackexception: error while committing transaction [error] application -   ! @6mjac6klf - internal server error, (post) [/customers/9/account?csrftoken=fe225b185b9c5ee9f48d58180d0885ca7118d7fd-1435656024963-c42071a398c0e4c84c7682d0] ->  play.api.application$$anon$1: execution exception[[runtimeexception: javax.persistence.rollbackexception: error while committing transaction]]     @ play.api.application$class.handleerror(application.scala:296) ~[play_2.11-2.3.7.jar:2.3.7]     @ play.api.defaultapplication.handleerror(application.scala:402) [play_2.11-2.3.7.jar:2.3.7]     @ play.core.server.netty.playdefaultupstreamhandler$$anonfun$3$$anonfun$applyorelse$4.apply(playdefaultupstreamhandler.scala:320) [play_2.11-2.3.7.jar:2.3.7]     @ play.core.server.netty.playdefaultupstreamhandler$$anonfun$3$$anonfun$applyorelse$4.apply(playdefaultupstreamhandler.scala:320) [play_2.11-2.3.7.jar:2.3.7]     @ scala.option.map(option.scala:145) [scala-library-2.11.4.jar:na] caused by: java.lang.runtimeexception: javax.persistence.rollbackexception: error while committing transaction     @ play.db.jpa.jpa.withtransaction(jpa.java:111) ~[play-java-jpa_2.11-2.3.7.jar:2.3.7]     @ controllers.admin.customers.updateaccountstates(customers.java:86) ~[classes/:na]     @ admin.routes$$anonfun$routes$1$$anonfun$applyorelse$21$$anonfun$apply$21.apply(routes_routing.scala:952) ~[classes/:na]     @ admin.routes$$anonfun$routes$1$$anonfun$applyorelse$21$$anonfun$apply$21.apply(routes_routing.scala:952) ~[classes/:na]     @ play.core.router$handlerinvokerfactory$$anon$4.resultcall(router.scala:264) ~[play_2.11-2.3.7.jar:2.3.7] caused by: javax.persistence.rollbackexception: error while committing transaction     @ org.hibernate.jpa.internal.transactionimpl.commit(transactionimpl.java:94) ~[hibernate-entitymanager-4.3.10.final.jar:4.3.10.final]     @ play.db.jpa.jpa.withtransaction(jpa.java:141) ~[play-java-jpa_2.11-2.3.7.jar:2.3.7]     @ play.db.jpa.jpa.withtransaction(jpa.java:104) ~[play-java-jpa_2.11-2.3.7.jar:2.3.7]     @ controllers.admin.customers.updateaccountstates(customers.java:86) ~[classes/:na]     @ admin.routes$$anonfun$routes$1$$anonfun$applyorelse$21$$anonfun$apply$21.apply(routes_routing.scala:952) ~[classes/:na] caused by: javax.persistence.persistenceexception: org.hibernate.exception.constraintviolationexception: not execute statement     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1763) ~[hibernate-entitymanager-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1677) ~[hibernate-entitymanager-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.jpa.internal.transactionimpl.commit(transactionimpl.java:82) ~[hibernate-entitymanager-4.3.10.final.jar:4.3.10.final]     @ play.db.jpa.jpa.withtransaction(jpa.java:141) ~[play-java-jpa_2.11-2.3.7.jar:2.3.7]     @ play.db.jpa.jpa.withtransaction(jpa.java:104) ~[play-java-jpa_2.11-2.3.7.jar:2.3.7] caused by: org.hibernate.exception.constraintviolationexception: not execute statement     @ org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:72) ~[hibernate-core-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) ~[hibernate-core-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:126) ~[hibernate-core-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:112) ~[hibernate-core-4.3.10.final.jar:4.3.10.final]     @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.executeupdate(resultsetreturnimpl.java:211) ~[hibernate-core-4.3.10.final.jar:4.3.10.final] caused by: com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: cannot add or update child row: foreign key constraint fails (`cg`.`user_aud`, constraint `fk_97pph94d4cb7qah5aygmmll2y` foreign key (`rev`) references `revinfo` (`rev`))     @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:1.7.0_71]     @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) ~[na:1.7.0_71]     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) ~[na:1.7.0_71]     @ java.lang.reflect.constructor.newinstance(constructor.java:526) ~[na:1.7.0_71]     @ com.mysql.jdbc.util.handlenewinstance(util.java:377) ~[mysql-connector-java-5.1.34.jar:5.1.34] 

it seams because the rev entry not created correctly not able create user revision.

i don't understand why is. seams happen when 'newrevision' throws exception, put should not.

thanks help!


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -