I am trying to implement a two phase atomic commit or rollback pattern. The steps are:
read database and populate a ui form
enter changes in the form submit for update and application level validate
do one of two actions
a. commit the multiple changes in one transaction
b. rollback the multiple changes to discard
These steps when done with a commit action work well, database read, form populated and updated, changes update the database.
When these steps are done with a rollback action, the behaviour is identical except an exception is thrown at userTransaction.rollback()
[org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorTrackingImpl] (default task-30) HHH000451:
Transaction afterCompletion called by a background thread; delaying afterCompletion processing until the original thread can handle it.
[status=4]
(default task-30) sessionAbort ex org.hibernate.HibernateException: Transaction was rolled back in a different thread!
Why don't I get an exception thrown when I commit? Each submit of the form has its own thread, but I don't see a multithread issue. I am not sure where to focus my investigation next. MySql or Wildfly or JPA/Hibernate?
Versions are:
java version "1.7.0_07"
ejb3
wildfly-8.2.0.Final
mysqladmin Ver 8.42 Distrib 5.5.21, for Linux on x86_64
RichFaces 4.5.4
Using dialect:org.hibernate.dialect.MySQL5Dialect
Sudo code is:
#TransactionManagement(TransactionManagementType.BEAN)
#Stateful(mappedName = "testSession")
#SessionScoped
#TransactionAttribute(value = TransactionAttributeType.REQUIRED)
public class TestSession {
#PersistenceContext(unitName="MySqlXA",type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;
#Resource private UserTransaction userTransaction;
First request/ thread one
userTransaction.begin();
Query query = entityManager.createQuery(sqlQuery);
List<SomeTable> queryResult = (List<SomeTable>)query.getResultList();
populate a SessionScoped ManagedBean
user think time
make updates through the UI and submit
Second request / thread two
TableOneRow tableOneRow = new TableOneRow(someStuff);
TableTwoRow tableTwoRow = entityManager.find(otherStuff);
entityManager.persist(tableOneRow);
entitymanager.merge(tableTwoRow);
Third request / thread three submit for commit
userTransaction.commit();
or Third request / thread three submit for abort
userTransaction.rollback();
Thanks in advance
With further research and experimentation, it looks like the cleanest way to discard a set of updates is to call entityManager.clear().
See below for a log of three tests and the relevant code. The first group of find,update,commit is my baseline of a good update. The second group of find,update,abort results in the HHH000451 exception. The last bit is the abort portion but using EntityManager clear instead.
2017-03-23 16:48:55,425 DEBUG [view.TestPage] (default task-21) find
2017-03-23 16:48:55,426 TRACE [ejb.session.TestPageSession] (default task-21) findNameAddress for addrId 5
2017-03-23 16:48:55,426 TRACE [ejb.session.TestPageSession] (default task-21) entityManager.find
2017-03-23 16:48:55,465 TRACE [ejb.session.TestPageSession] (default task-21) findNameAddress success true
2017-03-23 16:49:49,714 DEBUG [view.TestPage] (default task-24) update
2017-03-23 16:49:49,714 TRACE [ejb.session.TestPageSession] (default task-24) updateFirstLastName to One, For
2017-03-23 16:49:49,715 TRACE [ejb.session.TestPageSession] (default task-24) userTransaction.begin
2017-03-23 16:49:49,716 TRACE [ejb.session.TestPageSession] (default task-24) userTransaction.begin success true
2017-03-23 16:49:49,716 TRACE [ejb.session.TestPageSession] (default task-24) findNameAddress for addrId 5
2017-03-23 16:49:49,716 TRACE [ejb.session.TestPageSession] (default task-24) entityManager.find
2017-03-23 16:49:49,716 TRACE [ejb.session.TestPageSession] (default task-24) findNameAddress success true
2017-03-23 16:49:49,716 TRACE [ejb.session.TestPageSession] (default task-24) entityManager.merge
2017-03-23 16:49:49,721 TRACE [ejb.session.TestPageSession] (default task-24) updateFirstLastName success true
2017-03-23 16:50:19,652 DEBUG [view.TestPage] (default task-25) commit
2017-03-23 16:50:19,654 TRACE [ejb.session.TestPageSession] (default task-25) userTransaction.commit
2017-03-23 16:50:19,726 TRACE [ejb.session.TestPageSession] (default task-25) userTransaction.commit success true
2017-03-23 16:50:50,740 DEBUG [view.TestPage] (default task-26) find
2017-03-23 16:50:50,741 TRACE [ejb.session.TestPageSession] (default task-26) findNameAddress for addrId 5
2017-03-23 16:50:50,741 TRACE [ejb.session.TestPageSession] (default task-26) entityManager.find
2017-03-23 16:50:50,741 TRACE [ejb.session.TestPageSession] (default task-26) findNameAddress success true
2017-03-23 16:51:12,735 DEBUG [view.TestPage] (default task-29) update
2017-03-23 16:51:12,735 TRACE [ejb.session.TestPageSession] (default task-29) updateFirstLastName to two, For
2017-03-23 16:51:12,735 TRACE [ejb.session.TestPageSession] (default task-29) userTransaction.begin
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) userTransaction.begin success true
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) findNameAddress for addrId 5
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) entityManager.find
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) findNameAddress success true
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) entityManager.merge
2017-03-23 16:51:12,736 TRACE [ejb.session.TestPageSession] (default task-29) updateFirstLastName success true
2017-03-23 16:51:40,888 DEBUG [view.TestPage] (default task-30) abort
2017-03-23 16:51:40,889 TRACE [ejb.session.TestPageSession] (default task-30) userTransaction.rollback
2017-03-23 16:51:40,890 WARN [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorTrackingImpl] (default task-30) HHH000451: Transaction afterCompletion called by a background thread; delaying afterCompletion processing until the original thread can handle it. [status=4]
2017-03-23 16:51:40,891 TRACE [ejb.session.TestPageSession] (default task-30) userTransaction.rollback success true
2017-03-23 16:54:08,623 DEBUG [view.TestPage] (default task-12) abort
2017-03-23 16:54:08,624 TRACE [ejb.session.TestPageSession] (default task-12) entityManager.clear
2017-03-23 16:54:08,625 TRACE [ejb.session.TestPageSession] (default task-12) entityManager.clear success true
package com.gregdata.session;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.transaction.UserTransaction;
import org.jboss.logging.Logger;
import com.gregdata.model.Nameaddress;
#TransactionManagement(TransactionManagementType.BEAN)
#Stateful(mappedName = "localTestSession")
#SessionScoped
#TransactionAttribute(value = TransactionAttributeType.REQUIRED)
public class TestPageSession implements TestPageSessionLocal {
#PersistenceContext(unitName="MySqlStocksXA",
type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;
#Resource private UserTransaction userTransaction;
private Nameaddress nameaddress;
private boolean transactionBegun;
private Logger logger;
public TestPageSession() {
logger = Logger.getLogger(this.getClass());
}
#PostConstruct
public void initialize() {
}
public EntityManager getEntityManager() {
return entityManager;
}
public Nameaddress findNameaddress(int addrId)
{
Nameaddress nameaddress = null;
boolean success = false;
logger.trace("findNameAddress for addrId "+addrId);
try {
logger.trace("entityManager.find");
nameaddress = entityManager.find(Nameaddress.class, addrId);
success = true;
} catch (Exception ex)
{
logger.warn("findNameAddress ex: "+ex.getMessage());
success = true;
}
logger.trace("findNameAddress success "+success);
return nameaddress;
}
public boolean updateFirstLastName(int addrId, String firstName, String lastName)
{
boolean success = false;
logger.trace("updateFirstLastName to "+firstName+", "+lastName);
try
{
beginTransaction();
nameaddress = findNameaddress(addrId);
if ( nameaddress == null)
{
throw new Exception("Nameaddress id "+addrId+" not found");
}
nameaddress.setFirstName(firstName);
nameaddress.setLastName(lastName);
logger.trace("entityManager.merge");
entityManager.merge(nameaddress);
success = true;
} catch (Exception ex)
{
logger.warn("updateFirstLastName ex: "+ex.getMessage());
success = false;
}
logger.trace("updateFirstLastName success "+success);
return success;
}
public boolean beginTransaction()
{
boolean success = false;
if (transactionBegun) return true;
logger.trace("userTransaction.begin");
try
{
userTransaction.begin();
success = true;
transactionBegun = true;
} catch(Exception ex)
{
logger.warn("userTransaction.begin ex "+ex.getMessage());
success = false;
}
logger.trace("userTransaction.begin success "+success);
return success;
}
public boolean commitTransaction()
{
boolean success = false;
logger.trace("userTransaction.commit");
try
{
userTransaction.commit();
success = true;
transactionBegun = false;
} catch(Exception ex)
{
logger.warn("userTransaction.commit ex "+ex.getMessage());
success = false;
transactionBegun = false;
}
logger.trace("userTransaction.commit success "+success);
return success;
}
public boolean abortTransaction()
{
boolean success = false;
logger.trace("userTransaction.rollback");
try
{
userTransaction.rollback();
success = true;
transactionBegun = false;
} catch(Exception ex)
{
logger.warn("userTransaction.rollback ex "+ex.getMessage());
transactionBegun = false;
success = false;
}
logger.trace("userTransaction.rollback success "+success);
return success;
}
public boolean clearEntityManager() {
boolean success = false;
logger.trace("entityManager.clear");
try {
entityManager.clear();
success = true;
} catch (Exception ex) {
logger.warn("clearEntityManager ex: "+ex.getMessage());
}
logger.trace("entityManager.clear success "+success);
return success;
}
}
Related
I want to create a ENUM which holds different statuses for possible database values and use them also to generate possible drop down statuses in FE:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
public enum BusinessCustomersStatus {
A("active", "Active"),
O("onboarding", "Onboarding"),
NV("not_verified", "Not Verified"),
V("verified", "Verified"),
S("suspended", "Suspended"),
I("inactive", "Inactive");
private String shortName;
private String fullName;
BusinessCustomersStatus(String shortName, String fullName) {
this.shortName = shortName;
this.fullName = fullName;
}
// Define the status field as the enum representation by using #JsonValue
#JsonValue
public String getShortName() {
return shortName;
}
#JsonValue
public String getFullName() {
return fullName;
}
// Use the fromStatus method as #JsonCreator
#JsonCreator
public static BusinessCustomersStatus fromStatus(String statusText) {
for (BusinessCustomersStatus status : values()) {
if (status.getShortName().equalsIgnoreCase(statusText)) {
return status;
}
}
throw new UnsupportedOperationException(String.format("Unknown status: '%s'", statusText));
}
}
Full code:
https://github.com/rcbandit111/Search_specification_POC/blob/main/src/main/java/org/merchant/database/service/businesscustomers/BusinessCustomersStatus.java
But when I make a POST request to add a new record I get this error:
21:36:52.033 [http-nio-8000-exec-1] DEBUG HttpEntityMethodProcessor[traceDebug:91] - Writing [org.merchant.dto.tickets.TicketsFullDTO#1c7e1a52]
21:36:52.034 [http-nio-8000-exec-1] WARN DefaultHandlerExceptionResolver[logException:207] - Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Problem with definition of [AnnotedClass org.merchant.database.service.tickets.TicketStatus]: Multiple 'as-value' properties defined ([method org.merchant.database.service.tickets.TicketStatus#getFullName()] vs [method org.merchant.database.service.tickets.TicketStatus#getShortName()]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Problem with definition of [AnnotedClass org.merchant.database.service.tickets.BusinessCustomersStatus]: Multiple 'as-value' properties defined ([method org.merchant.database.service.tickets.BusinessCustomersStatus#getFullName()] vs [method org.merchant.database.service.tickets.BusinessCustomersStatus#getShortName()]) (through reference chain: org.merchant.dto.tickets.TicketsFullDTO["status"])]
21:36:52.034 [http-nio-8000-exec-1] DEBUG OpenEntityManagerInViewInterceptor[afterCompletion:111] - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
21:36:52.034 [http-nio-8000-exec-1] DEBUG DispatcherServlet[logResult:1131] - Completed 500 INTERNAL_SERVER_ERROR
21:36:52.035 [http-nio-8000-exec-1] DEBUG DispatcherServlet[traceDebug:91] - "ERROR" dispatch for POST "/api/error", parameters={}
21:36:52.035 [http-nio-8000-exec-1] DEBUG RequestMappingHandlerMapping[getHandler:522] - Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
21:36:52.035 [http-nio-8000-exec-1] DEBUG OpenEntityManagerInViewInterceptor[preHandle:86] - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
21:36:52.036 [http-nio-8000-exec-1] DEBUG HttpEntityMethodProcessor[writeWithMessageConverters:268] - Using 'application/json', given [application/json, text/plain, */*] and supported [application/json, application/*+json, application/json, application/*+json]
21:36:52.036 [http-nio-8000-exec-1] DEBUG HttpEntityMethodProcessor[traceDebug:91] - Writing [{timestamp=Wed Oct 27 21:36:52 UTC 2021, status=500, error=Internal Server Error, path=/api/manageme (truncated)...]
21:36:52.036 [http-nio-8000-exec-1] DEBUG OpenEntityManagerInViewInterceptor[afterCompletion:111] - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
21:36:52.037 [http-nio-8000-exec-1] DEBUG DispatcherServlet[logResult:1127] - Exiting from "ERROR" dispatch, status 500
Multiple 'as-value' properties defined ^C22:18:41.117 [SpringApplicationShutdownHook] DEBUG ApplicationAvailabilityBean[onApplicationEvent:77] - Application availability state ReadinessState changed from ACCEPTING_TRAFFIC to REFUSING_TRAFFIC
Note that I have changed TicketStatus with BusinessCustomersStatus into the error stack.
When I make a request I send this payload:
{"title":"ascascasc","description":"ascascasc","status":"assigned","submitDate":"2021-10-13T00:00:00.000Z","category":"service","severity":"normal"}
Do you know how I can solve this issue?
it may work if changed like this
public String getShortName() {
return shortName;
}
#JsonValue
public String getFullName() {
return fullName;
}
I'm working on a project for my programming class and the teacher encourages to use stackoverflow for assistance. My problem is as follows: in my if with sResult.next() is coming back false. I'm trying to obtain one row from my derby database.
I have verified my productUuid is obtaining a UUID, preparedstatement is active. I have checked that my findAll for the query is working and it is.
The interceptor is supposed to return the class name that is being used.
My query:
private static final String QUERY_02 =
"SELECT oid, product_name, product_desc, product_price, product_sku, product_inv FROM PRODUCT WHERE oid=?";
My UUIDUtils:
public class UUIDUtils {
public static UUID asUuid(byte[] bytes) {
final ByteBuffer bb = ByteBuffer.wrap(bytes);
final long firstLong = bb.getLong();
final long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
public static byte[] asBytes(UUID uuid) {
final ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
My singleProduct:
public ProductDTO singleProduct(UUID productUuid) throws MyStoreException {
log().trace("Entered singleProduct()");
ProductDTO sProduct = null;
try (final Connection connection = datasource.getConnection();
final PreparedStatement sPre = connection.prepareStatement(QUERY_02);) {
sPre.setBytes(1, UUIDUtils.asBytes(productUuid));
log().trace("PreparedStatment connection is active: {}", !sPre.isClosed());
log().trace("productUuid passed through ProductQueryImpl: {}" , productUuid);
ResultSet sResult = sPre.executeQuery();
if(sResult.next()) {
sProduct = new ProductDTO(productUuid,
sResult.getString("product_name"),
sResult.getString("product_desc"),
sResult.getDouble("product_price"),
sResult.getString("product_sku"),
sResult.getInt("product_inv"));
}else {
log().error("Product not found");
}
return sProduct;
}catch(final SQLException ex2) {
log().error(ex2.getMessage(), ex2);
throw new MyStoreException(ex2.getMessage());
}
}
My Console:
00:05:04,092 TRACE [ca.sait.mystore.mvc.model.ProductModel] (default task-1) Entered postConstruct()
00:05:04,094 TRACE [ca.sait.mystore.interceptors.LogInterceptors] (default task-1) Entered logInterceptor(context)
00:05:04,094 DEBUG [ca.sait.mystore.interceptors.LogInterceptors] (default task-1) Method Name: singleProduct
00:05:04,094 TRACE [ca.sait.mystore.dao.ProductQueryImpl] (default task-1) Entered singleProduct()
00:05:04,096 TRACE [ca.sait.mystore.dao.ProductQueryImpl] (default task-1) PreparedStatment connection is active: true
00:05:04,096 TRACE [ca.sait.mystore.dao.ProductQueryImpl] (default task-1) productUuid passed through ProductQueryImpl: 00b6d373-af18-54ed-f8c9-7f9d986a834a
00:05:04,097 ERROR [ca.sait.mystore.dao.ProductQueryImpl] (default task-1) Product not found
00:05:04,098 DEBUG [ca.sait.mystore.interceptors.LogInterceptors] (default task-1) Returning Null
00:05:04,098 TRACE [ca.sait.mystore.interceptors.LogInterceptors] (default task-1) Exited logInterceptor(context)
00:05:04,099 TRACE [ca.sait.mystore.mvc.model.ProductModel] (default task-1) Following UUID passed through Model: 00b6d373-af18-54ed-f8c9-7f9d986a834a
00:05:04,099 TRACE [ca.sait.mystore.mvc.model.ProductModel] (default task-1) Exited postConstruct()
Why even if exception is thrown data is not rolledback from database
I set rollbackFor = Exception.class and it still doesn't rollback data when second visit is put into databse.
#EnableTransactionManagement
#Service
public class VisitService {
private final static Logger logger = LoggerFactory.getLogger(VisitService.class);
private final VisitRepository visitRepository;
public VisitService(VisitRepository visitRepository) {
this.visitRepository = visitRepository;
}
public List<Visit> findAllByDate(LocalDateTime date){
return visitRepository.findAllByDate(date);
}
#Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = RuntimeException.class, propagation = Propagation.REQUIRED)
public Visit save(#Valid Visit visit) {
logger.info("Inside visitService");
visit.setPayed(false);
if (visit.getPrice().intValue() > 1000)
visit.setDiscount(new BigDecimal(0.05));
else visit.setDiscount(new BigDecimal(0.00));
visitRepository.save(visit);
if(findAllByDate(visit.getDate()).size()>1)
throw new RuntimeException();
return null;
}
}
tried with configuration to transaction
#Configuration
#ConditionalOnClass({PlatformTransactionManager.class})
#AutoConfigureAfter({JtaAutoConfiguration.class, HibernateJpaAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, Neo4jDataAutoConfiguration.class})
#EnableConfigurationProperties({TransactionProperties.class})
public class TransactionAutoConfiguration {
}
part of stack trace
2018-12-08 23:16:23.653 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.TransactionInterceptor : Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
Hibernate: insert into visits (visit_date, description, discount, payed, pet_id, price, vet_id) values (?, ?, ?, ?, ?, ?, ?)
2018-12-08 23:16:23.663 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.TransactionInterceptor : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
2018-12-08 23:16:23.664 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.TransactionInterceptor : Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAllByDate]
Hibernate: select visit0_.id as id1_6_, visit0_.visit_date as visit_da2_6_, visit0_.description as descript3_6_, visit0_.discount as discount4_6_, visit0_.payed as payed5_6_, visit0_.pet_id as pet_id6_6_, visit0_.price as price7_6_, visit0_.vet_id as vet_id8_6_ from visits visit0_ where visit0_.visit_date=?
2018-12-08 23:16:23.685 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.TransactionInterceptor : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAllByDate]
2018-12-08 23:16:23.685 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.TransactionInterceptor : Completing transaction for [org.springframework.samples.petclinic.services.VisitService.save] after exception: java.lang.RuntimeException
2018-12-08 23:16:23.685 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.RuleBasedTransactionAttribute : Applying rules to determine whether transaction should rollback on java.lang.RuntimeException
2018-12-08 23:16:23.685 TRACE 3360 --- [nio-8080-exec-2] o.s.t.i.RuleBasedTransactionAttribute : Winning rollback rule is: RollbackRuleAttribute with pattern [java.lang.RuntimeException]
2018-12-08 23:16:23.690 DEBUG 3360 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Failed to complete request: java.lang.RuntimeException
2018-12-08 23:16:23.698 ERROR 3360 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException] with root cause
java.lang.RuntimeException: null
There is visitRepository with default annnotations
VisitRepository :
public interface VisitRepository extends Repository<Visit, Integer> {
Visit save(Visit visit) throws DataAccessException;
List<Visit> findByPetId(Integer petId);
Visit findById(Integer visitId);
#Transactional(readOnly = true)
List<Visit> findAllByDate(LocalDateTime date);
Visit findByDate(LocalDateTime date);
}
I use JHipster to make a simple app and write a service, code as follows:
#Service
#Transactional
public class OperateQueueActionService {
#Transactional(rollbackFor = Throwable.class)
public OperateQueueDTO apply(OperateQueueDTO operateQueueDTO, QueueEventType queueEventType, String deskNo) {
StateMachine<QueueStatus, QueueEventType> stateMachine = operateQueueActionMachineService.getStateMachine();
try { QueueEventDTO operateQueueEventDTO = operateQueueUtils.saveQueueEvent(operateQueueDTO, queueEventType, deskNo);
......in process will throw RuntimeException.
} finally {
stateMachine.stop();
}
}
}
I want the transaction to rollback and not save queueEvent, but the record is saved in the database. This is the transaction log:
[2018-07-24 12:04:51.861] [XNIO-2 task-6] WARN
o.s.s.l.CompositeStateMachineListener -Error during stateContext
java.lang.RuntimeException: 无效状态 at
com.higoee.queue.state.utils.OperateQueueStateMachineLogListener.stateContext(OperateQueueStateMachineLogListener.java:58)
at java.lang.Thread.run(Thread.java:745) [2018-07-24 12:04:51.871]
[XNIO-2 task-6] INFO c.h.q.s.u.OperateQueueStateMachineLogListener
-4d667539-3316-491d-a0db-240e29b0fcae状态机状态为:STATEMACHINE_STOP [2018-07-24 12:04:51.872] [XNIO-2 task-6] DEBUG
o.s.orm.jpa.JpaTransactionManager -Initiating transaction commit
[2018-07-24 12:04:51.874] [XNIO-2 task-6] DEBUG
o.s.orm.jpa.JpaTransactionManager -Committing JPA transaction on
EntityManager
JPA config have not problem,spring state machine had been catch the exception which was thrown in StateMachineListenerAdapter.
I have a method loading up a persistent object and then have it updated. When I use flush(), the process hangs with no errors. Any idea?
Code:
public Task changeStatus(Long taskNo, String status) {
Session sess = HibernateUtil
.getSessionFactory()
.openSession();
Task task = (Task) sess.load(Task.class, taskNo);
task.setStatus(status);
sess.flush();
return task;
}
The log shows this:
INFO: 09:33:05,329 DEBUG Printer:83 - listing entities:
INFO: 09:33:05,329 DEBUG Printer:90 - models.Task{userByAssignedToCheck=null, client=models.Client#1, status=Withdrawn, datasets=, urgent=false, taskLogs=, userByCheckedBy=null, dateReceived=29 August 2013, dateCompleted=null, fee=null, onTime=false, userByOriginatorId=models.User#1, taskCat=null, userByAssignedToWork=null, source=null, originatorOld=null, description=null, userByCompletedBy=null, method=null, taskNo=11492, dueDate=null, requestVia=null, comments=}
INFO: 09:33:05,329 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
INFO: 09:33:05,329 DEBUG SQL:401 - /* update models.Task */ update DBAKZHU0.INFO_TASK set CLIENTNO=?, ASSIGNEDTOCHECK=?, TASKTYPENO=?, COMPLETEDBY=?, CHECKEDBY=?, ORIGINATORID=?, SOURCENO=?, ASSIGNEDTOWORK=?, METHOD=?, REQUESTVIA=?, DATERECEIVED=?, DATECOMPLETED=?, DUEDATE=?, STATUS=?, ORIGINATOROLD=?, ONTIME=?, URGENT=?, FEE=?, DESCRIPTION=? where TASKNO=?
INFO: Hibernate: /* update models.Task */ update DBAKZHU0.INFO_TASK set CLIENTNO=?, ASSIGNEDTOCHECK=?, TASKTYPENO=?, COMPLETEDBY=?, CHECKEDBY=?, ORIGINATORID=?, SOURCENO=?, ASSIGNEDTOWORK=?, METHOD=?, REQUESTVIA=?, DATERECEIVED=?, DATECOMPLETED=?, DUEDATE=?, STATUS=?, ORIGINATOROLD=?, ONTIME=?, URGENT=?, FEE=?, DESCRIPTION=? where TASKNO=?