CUTR-at-USF / gtfs-realtime-validator

Java-based tool that validates General Transit Feed Specification (GTFS)-realtime feeds. See https://github.com/MobilityData/gtfs-realtime-validator for the latest!
Other
92 stars 40 forks source link

javax.persistence.OptimisticLockException on "mvn install" and old database #78

Closed barbeau closed 7 years ago

barbeau commented 7 years ago

Summary:

On my laptop, I'm getting the following error when I try to do mvn clean install -U on the master branch and https://github.com/CUTR-at-USF/gtfs-realtime-validator/pull/77 in the middle of the tests:

If location_type is used in stops.txt, all stops referenced in stop_times.txt must have location_type of 0
All stop_ids referenced in GTFS-rt feeds must have the location_type = 0
javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
        at org.hibernate.internal.ExceptionConverterImpl.wrapStaleStateException(ExceptionConverterImpl.java:212)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:86)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1411)
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1391)
        at edu.usf.cutr.gtfsrtvalidator.db.GTFSDB.commitAndCloseSession(GTFSDB.java:112)
        at edu.usf.cutr.gtfsrtvalidator.db.GTFSDB.InitializeDB(GTFSDB.java:91)
        at edu.usf.cutr.gtfsrtvalidator.api.resource.GtfsFeedTest.setUp(GtfsFeedTest.java:41)
        at junit.framework.TestCase.runBare(TestCase.java:139)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:129)
        at junit.framework.TestSuite.runTest(TestSuite.java:252)
        at junit.framework.TestSuite.run(TestSuite.java:247)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
        at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:67)
        at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:54)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3119)
        at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2998)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3378)
        at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1405)
        ... 19 more
Table initialized successfully
http://gohart.org/google/google_transit.zip
GTFS File Downloaded Successfully
URL exists in database
Invalid URL
http://gohart.org/google/file_not_exist.zip

If I try to run the application I get the same error message, and it doesn't log data.

If I do a fresh clone of the repo, everything works fine.

Steps to reproduce:

Not sure - I'm guessing it has something to do with my local database files that were generated via previous builds (because starting from scratch works fine), so I'm attaching them. Then just run mvn install -U.

Expected behavior:

No errors should be thrown

Observed behavior:

Get above stack trace in the middle of tests.

Platform: Windows 10 Home 1607 with JDK 1.8.0_121 64bit

dbfiles.zip

barbeau commented 7 years ago

It looks like this is related to updating the schema in #77. #77 adds new columns as well as in hibernate.cfg.xml it adds the following line: <property name="hibernate.hbm2ddl.auto">update</property>

This makes sure the database schema matches the model classes. However, the master branch doesn't have this, so it drifted out of sync with the model classes when I switched branches. Going forward as long as we keep the above XML config line this issue should resolve itself and the model classes will always match the schema.