USEPA / emf

Emissions Modeling Framework (EMF)
6 stars 3 forks source link

error importing control measure database #133

Closed cseppan closed 1 year ago

cseppan commented 1 year ago

Affects EMF v4.2 on EPA server.

java.lang.NullPointerException at ControlMeasureDAO.removeSccs(ControlMeasureDAO.java:328)

CMDB import fails when trying to purge existing measures. Code was updated as part of Hibernate upgrades for v4.2.

cseppan commented 1 year ago

java.lang.IllegalStateException: Transaction already active at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:74) at org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:503) at gov.epa.emissions.framework.services.cost.ControlMeasureDAO.removeSccs(ControlMeasureDAO.java:324) at gov.epa.emissions.framework.services.cost.ControlMeasureDAO.remove(ControlMeasureDAO.java:151) at gov.epa.emissions.framework.services.cost.controlmeasure.io.CMImportTask.run(CMImportTask.java:168) at gov.epa.emissions.framework.services.GCEnforcerTask.run(GCEnforcerTask.java:23) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Thread.java:833)

Method ControlMeasureDAO.remove() already begins a transaction, then removeSccs() tries to begin another one.

cseppan commented 1 year ago

Commit be17702351e21bbba4160db803fa2872c9d2cd7e removes the attempts to create nested transactions from two functions.

removeSccs(int[] sectorIds, Session session) removeEfficiencyRecords(int[] sectorIds, Session session)

I confirmed that these are only called from the remove function that has already set up a transaction.

cseppan commented 1 year ago

After getting past the purge problem, control measures are still failing to import

org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.makePhysicalTransactionDelegate(JtaTransactionCoordinatorImpl.java:257) at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.getTransactionDriverControl(JtaTransactionCoordinatorImpl.java:231) at org.hibernate.engine.transaction.internal.TransactionImpl.(TransactionImpl.java:46) at org.hibernate.internal.AbstractSharedSessionContract.accessTransaction(AbstractSharedSessionContract.java:463) at org.hibernate.internal.AbstractSharedSessionContract.getTransaction(AbstractSharedSessionContract.java:456) at org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:502) at gov.epa.emissions.framework.services.persistence.HibernateFacade.isUsed(HibernateFacade.java:108) at gov.epa.emissions.framework.services.cost.ReferencesDAO.descriptionUsed(ReferencesDAO.java:73) at gov.epa.emissions.framework.services.cost.controlmeasure.io.CMReferenceImporter.generateCorrectedReferenceMap(CMReferenceImporter.java:90) at gov.epa.emissions.framework.services.cost.controlmeasure.io.CMReferenceImporter.run(CMReferenceImporter.java:71) at gov.epa.emissions.framework.services.cost.controlmeasure.io.ControlMeasuresImporter.runReference(ControlMeasuresImporter.java:318) at gov.epa.emissions.framework.services.cost.controlmeasure.io.ControlMeasuresImporter.run(ControlMeasuresImporter.java:122) at gov.epa.emissions.framework.services.cost.controlmeasure.io.CMImportTask.run(CMImportTask.java:199) at gov.epa.emissions.framework.services.GCEnforcerTask.run(GCEnforcerTask.java:23) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Thread.java:833)

cseppan commented 1 year ago

Steps to reproduce:

cseppan commented 1 year ago

Commit a9f3d1c changes ReferencesDAO to use gov.epa.emissions.framework.services.persistence.HibernateSessionFactory instead of gov.epa.emissions.commons.db.HibernateSessionFactory. This matches all other DAOs in the EMF project.

The Commons version of HibernateSessionFactory doesn't appear to be used in the EMF.

I've deployed the two code updates to fix the errors purging old control measures and importing the new measures.