I have several database tables where auto number field is populated from CUBA-FRAMEWORK without any problem except one where the number is incremented more than 1. Is there any specific reason why?
@Override
public void onBeforeInsert(JournalHeader entity) {
entity.setJournalNumber(unService.getNextNumber("Journal_Number"));
}
Searched for getNextNumber() in the whole project but only used to create unique sequence number containing different keys getNextNumber(“Journal_Number”), getNextNumber(“Material_Number”) etc, in 14 places. There is no use of getNextNumber() like this. Is there anything else I should check?
I am having some difficulty in running debug mode in this RC version. If I turn on debug mode from IntelliJ, I can’t run the application, this might be another issue, thanks for checking and advising too.
Here is snap-shot from app.log where i see some ERROR reported, does it indicate any related issue?
2016-09-08 02:09:25.108 ERROR [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Invoking long com.haulmont.cuba.core.app.UniqueNumbersService.getNextNumber(String) from another service
2016-09-08 02:09:25.118 WARN [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Open transaction left in UniqueNumbersService.getNextNumber(..)
2016-09-08 02:09:25.170 ERROR [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Invoking long com.haulmont.cuba.core.app.UniqueNumbersService.getNextNumber(String) from another service
2016-09-08 02:09:25.171 WARN [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Open transaction left in UniqueNumbersService.getNextNumber(..)
2016-09-08 02:09:25.186 ERROR [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Invoking long com.haulmont.cuba.core.app.UniqueNumbersService.getNextNumber(String) from another service
2016-09-08 02:09:25.187 WARN [http-nio-8080-exec-56/myproj-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Open transaction left in UniqueNumbersService.getNextNumber(..)
2016-09-08 02:09:42.578 DEBUG [http-nio-8080-exec-24/myproj/admin] com.haulmont.cuba.web.App - Ping session
2016-09-08 02:10:03.759 DEBUG [scheduler-7] com.haulmont.cuba.core.app.LockManager - Expiring locks
The number is increased by 3 each time i create a record. I have a Listener for the composite entity, noticed that the listener is called 3 times resulting corresponding update to another entity that I have used inside, take a look at the listener.
@Override
public void onBeforeInsert(JournalLine entity, EntityManager entityManager) {
updateInsertBalance(entity);
}
private void updateInsertBalance(JournalLine operation) {
EntityManager em = persistence.getEntityManager();
TypedQuery<GlAccountsBalance> query = em.createQuery("select e from mydb$GlAccountsBalance e " +
"where e.glAccounts.id = ?1 AND e.company.id = ?2 AND e.financialYear.id = ?3 AND e.financialPeriod.id = ?4", GlAccountsBalance.class);
query.setParameter(1, operation.getGlAccounts().getId())
.setParameter(2, operation.getJournal().getCompany().getId())
.setParameter(3, operation.getJournal().getFinancialYear().getId())
.setParameter(4, operation.getJournal().getFinancialPeriod().getId())
.setView(GlAccountsBalance.class, "glAccountsBalance-view");
GlAccountsBalance list = query.getFirstResult();
if(list==null) {
BigDecimal a = new BigDecimal(0);
GlAccountsBalance balance = metadata.create(GlAccountsBalance.class);
balance.setCompany(operation.getJournal().getCompany());
balance.setFinancialYear(operation.getJournal().getFinancialYear());
balance.setFinancialPeriod(operation.getJournal().getFinancialPeriod());
if(operation.getDebit().doubleValue()>0){
balance.setAmount(a.add(operation.getDebit()));
}else{
balance.setAmount(a.subtract(operation.getCredit()));
}
em.persist(balance);
}else{
BigDecimal a=new BigDecimal(0);
if(list.getAmount() != null){
a= list.getAmount();
}
if(operation.getDebit().doubleValue()>0){
list.setAmount(a.add(operation.getDebit()));
}else{
list.setAmount(a.subtract(operation.getCredit()));
}
}
}