kuros / random-jpa

Create random test data for JPA/Hibernate entities.
GNU General Public License v3.0
26 stars 4 forks source link

Add Debugging to the creation plan so failures can be tracked down. #35

Closed tcurrie closed 5 years ago

tcurrie commented 5 years ago

As the execution plan is executed, Random JPA should log the entities it is trying to create, before it creates them so that, when a sql exception is thrown, then this debug list will show WHERE in the tree it occured, and the factory context can be corrected.

For instance, this is what a typical failure looks like, if I'm reading this correctly, it ran into a constraint violation on the 9th object that it was attempting to create in the tree. But there is no constraint name or Pojo name, and there are only debug logs on success, no debug logs on a per line item basis:

javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372) at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988) at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421) at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671) at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:727) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:490) at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:195) at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:179) at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:214) at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324) at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125) at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84) at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181) at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241) at com.sun.proxy.$Proxy82.persist(Unknown Source) at com.github.kuros.random.jpa.persistor.functions.PersistFunction.apply(PersistFunction.java:36) at com.github.kuros.random.jpa.persistor.functions.FunctionProcessor.findOrSave(FunctionProcessor.java:42) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:98) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:106) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:84) at com.github.kuros.random.jpa.persistor.EntityPersistorImpl.persist(EntityPersistorImpl.java:68) at com.github.kuros.random.jpa.JPAContextImpl.persist(JPAContextImpl.java:74) at com.cobalt.dap.random.jpa.generator.BaseContext.persist(BaseContext.java:41)

kuros commented 5 years ago

fixed with v1.0.2