Hello! I got some trouble. Try to run simple test:
@Test
public void getSimpleData() {
Transaction tx = persistence.createTransaction("additional");
try {
EntityManager em = persistence.getEntityManager("additional");
Query query = em.createQuery("select c from nl$Data c where c.id=1");
}catch (Exception ex){
ex.printStackTrace();
}finally {
tx.close();
}
}
And got exception:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: java.lang.AbstractMethodError
If create transaction like this (without additional storename) all work’s fine.
Transaction tx = persistence.createTransaction();
But I need create transaction to additional database and now I can’t do this.
My test container code:
package com.company.nl;
import com.haulmont.cuba.core.sys.AppContext;
import com.haulmont.cuba.testsupport.TestContainer;
import com.haulmont.cuba.testsupport.TestContext;
import com.haulmont.cuba.testsupport.TestDataSource;
import javax.naming.NamingException;
import java.util.ArrayList;
import java.util.Arrays;
public class SalesTestContainer extends TestContainer {
SalesTestContainer() {
super();
appComponents = new ArrayList<>(Arrays.asList(
"com.haulmont.cuba",
"com.haulmont.reports"
));
appPropertiesFiles = Arrays.asList(
"com/company/nl/app.properties");
dbDriver = "org.postgresql.Driver";
dbUrl = "**********";
dbUser = "**********";
dbPassword = "**********";
}
@Override
protected void initDataSources() {
super.initDataSources();
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
TestDataSource mydbDataSource
= new TestDataSource("**********", "***", "***");
TestContext.getInstance().bind(AppContext.getProperty("cuba.dataSourceJndiName_additional"), mydbDataSource);
} catch (ClassNotFoundException | NamingException e) {
throw new RuntimeException("Error initializing datasource", e);
}
}
public static class Common extends SalesTestContainer {
public static final SalesTestContainer.Common INSTANCE = new SalesTestContainer.Common();
private static volatile boolean initialized;
private Common() {
}
@Override
public void before() throws Throwable {
if (!initialized) {
super.before();
initialized = true;
}
setupContext();
}
@Override
public void after() {
cleanupContext();
// never stops - do not call super
}
}
}
Thanks!