Skip to content

Instantly share code, notes, and snippets.

@demoth
Created May 4, 2012 12:55
Show Gist options
  • Save demoth/2594642 to your computer and use it in GitHub Desktop.
Save demoth/2594642 to your computer and use it in GitHub Desktop.
16:49:51,812 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.at
s.internal.jta.resources.arjunacore.SynchronizationImple@5ef22784
java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.spbstu.cqc.ImportMapping.department -> org.spbstu.cqc.Department
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:611)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.spbstu.cqc.ImportMapping.department -> org.spbstu.cqc.Department
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:376)
at org.hibernate.engine.Cascade.cascade(Cascade.java:162)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
... 59 more
16:49:51,903 WARN [SeamPhaseListener] uncaught exception, passing to exception handler
java.lang.IllegalStateException: Could not commit transaction
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:625)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1401)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
... 49 more
Caused by: java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.spbstu.cqc.ImportMapping.department -> org.spbstu.cqc.Department
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:611)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
... 54 more
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.spbstu.cqc.ImportMapping.department -> org.spbstu.cqc.Department
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:376)
at org.hibernate.engine.Cascade.cascade(Cascade.java:162)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
... 59 more
public void importDepartments(EntityManager em, EntityManager iem) {
// вывод
List<String> log = new ArrayList<String>();
int foundParents = 0, notFoundDeps = 0, expiredIds = 0;
// ImportMapping по внешнему коду
List<ImportMapping> ims = em.createQuery("from ImportMapping i where i.epoch=:epoch")
.setParameter("epoch", 13).getResultList();
Map<String, ImportMapping> imMap = new HashMap<String, ImportMapping>();
for (ImportMapping i : ims) {
imMap.put(i.getExtId().trim(), i);
}
// наши подразделения по внутреннему ид
Map<Long, Department> intDepMap = new HashMap<Long, Department>();
List<Department> intDepList = em.createQuery("from Department d where d.epoch=:epoch")
.setParameter("epoch", 13).getResultList();
for (Department d : intDepList) {
intDepMap.put(d.getId(), d);
}
// наши факультеты по внутреннему ид
Map<Long, Faculty> intFacMap = new HashMap<Long, Faculty>();
List<Faculty> inFacList = em.createQuery("from Faculty")
.getResultList();
for (Faculty d : inFacList) {
intFacMap.put(d.getId(), d);
}
List<ViewDeps> deps = iem.createQuery("from ViewDeps").getResultList();
// внешние подразделения по коду
Map<String, ViewDeps> extDepsMap = new HashMap<String, ViewDeps>();
for (ViewDeps d : deps) {
extDepsMap.put(d.getCod().trim(), d);
}
Map<String, ImportMapping> newMappings = new HashMap<String, ImportMapping>();
Map<String, Department> newDepartment = new HashMap<String, Department>();
for (ViewDeps d : deps) {
if (d.getSubcod() == null || d.getCod() == null || d.getDName() == null)
continue;
log.add("\nОбрабатываем dep " + d.getDName().trim() + "[" + d.getCod().trim() + "]");
ImportMapping im;
// если нет маппинга то создать
if (!imMap.containsKey(d.getCod().trim())) {
im = new ImportMapping();
im.setExtName(d.getDName().trim());
im.setEpoch(DEBUG_EPOCH);
im.setExtId(d.getCod().trim());
log.add("\n-- маппинг не найдён.. создаём");
} else {
im = imMap.get(d.getCod().trim());
log.add("\n-- маппинг найдён!");
}
// Теперь есть ImportMapping (новый или старый).
// посмотрим, есть ли внутренний ид
if (im.getIntId() == null) {
log.add("\n-- маппинг пустой, создаём подразделение...");
// им есть, но ссылается на нуль
// нужно создать подразделение и сохранить его в им,
Department department = new Department();
department.setName(d.getDName().trim());
department.setEpoch(DEBUG_EPOCH);
// а затем положить им в newMappings, чтобы он сохранился
im.department = department;
newMappings.put(im.getExtId().trim(), im);
// родителя надо поставить потом, когда все подразделения будут в newDeps и newMappings
}
}
log.add("\nНовых маппингов: " + newMappings.size());
// теперь надо пройтись по всему и поставить родителей
List<ImportMapping> manyMappings = new ArrayList<ImportMapping>();
manyMappings.addAll(newMappings.values());
manyMappings.addAll(ims);
for (ImportMapping mapping : manyMappings) {
Department department;
log.add("\nОбрабатываем im " + mapping.getTableName());
// надо достать подразделение. Оно будет записано либо в поле department либо будет внутренный ID
if (mapping.department != null) {
department = mapping.department;
} else if ((mapping.getIntId() != null) && intDepMap.containsKey(mapping.getIntId())) {
department = intDepMap.get(mapping.getIntId());
} else {
//log.add("\nimportMapping's department was not found! extId=" + mapping.getExtId().trim());
log.add("\nподразделение маппинга не найдено, extId=" + mapping.getExtId().trim());
notFoundDeps++;
continue;
}
// надо найти родителя. всё через импорт маппинг
if (!extDepsMap.containsKey(mapping.getExtId().trim())) {
// ошибка!
//log.add("\next department was not found! extId=" + mapping.getExtId().trim());
log.add("\nмаппинг ссылается на несущ. внешнее подразделение, extId=" + mapping.getExtId().trim());
expiredIds++;
continue;
}
// задан ли код родителя во внешней базе?
if (extDepsMap.get(mapping.getExtId().trim()).getSubcod() == null) {
//System.out.println("ext department's parentId is null! extId=" + mapping.getExtId().trim());
log.add("\nparentId внешнего подразделения == null, extId=" + mapping.getExtId().trim());
continue;
}
String parentId = extDepsMap.get(mapping.getExtId().trim()).getSubcod().trim();
Object parent = null;
// сначала смотрим в свежедобавленные
if (newMappings.containsKey(parentId)) {
if (newMappings.get(parentId).getIntId() != null) { // проверить, выполняется ли когда нибудь?
//newMappings.get(parentId).department!=null
parent = intDepMap.get(newMappings.get(parentId).getIntId());
} else if (newMappings.get(parentId).department!=null) {
parent = newMappings.get(parentId).department;
}
} else if (imMap.containsKey(parentId) &&
imMap.get(parentId).getIntId() != null) {
if (!imMap.get(parentId).getTableName().equals("1")) {
if (intDepMap.containsKey(imMap.get(parentId).getIntId())) {
parent = intDepMap.get(imMap.get(parentId).getIntId());
}
} else {
// нужен ли нам родитель факультет
if (intFacMap.containsKey(imMap.get(parentId).getIntId())) {
parent = intFacMap.get(imMap.get(parentId).getIntId());
}
}
}
// нашли родителя
if (parent != null) {
foundParents++;
if (parent instanceof Department) {
department.setParentDepartment((Department) parent);
log.add("\n++ Найден родитель " + parent + " у " + department);
} else if (parent instanceof Faculty) {
department.setParentDepartment(null); // not a feature
department.setFaculty((Faculty) parent);
log.add("\n++ Найден родитель " + parent + " у " + department);
}
} else {
log.add("\n++ Не найден родитель у " + department + "[" + mapping.getExtId() + "]");
}
}
log.add("\nNot found deps: " + notFoundDeps);
log.add("\nExpired extIds: " + expiredIds);
log.add("\nFound parents: " + foundParents);
log.add("\nManyMappings size: " + manyMappings.size());
log.add("\nNew mappings size: " + newMappings.size());
try {
FileWriter fileWriter = new FileWriter("d:/temp/log_import.txt");
for (String s : log) {
fileWriter.append(s);
}
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
/* facesMessages.add("Not found deps: " + notFoundDeps);
facesMessages.add("expired extIds: " + expiredIds);
facesMessages.add("Found parents: " + foundParents);*/
// всё сохранить
// todo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment