"entity is not mapped" problem on intellij ultimate 2019.2
Hello, i am facing the following problem:
Whenever i try to run a testcase it fails to find the jpa entity.
The test case uses spring runner and the project is gradle-based.
I've changed the default layout as follows:
sourceSets {
main {
java {
srcDir 'src'
srcDir 'nfe-ws-gen'
srcDir 'netpoints-ws-gen'
srcDir 'mdfe-ws-gen'
srcDir 'cotamix-ws-gen'
}
resources { srcDir "src" }
output.resourcesDir = output.classesDir
}
test {
java {
srcDir "test/unit"
srcDir "test/integration"
srcDir "test/acceptance"
srcDir "test/resource"
srcDir "component"
}
resources {
srcDir "test/unit"
srcDir "test/integration"
srcDir "test/acceptance"
srcDir "test/resource"
srcDir "component"
}
}
}
when i try to run any JUnit test using intellij structure, i get an error like this:
org.hibernate.hql.internal.ast.QuerySyntaxException: RequisicaoTransacao is not mapped [select r from RequisicaoTransacao r, Inconsistencia i where r.transacaoPK.sequencial = i.sequencialTransacao and r.transacaoPK.data = i.dataTransacao and r.transacaoPK.numeroCaixa = i.numeroCaixa and r.transacaoPK.codigoLoja = i.loja.codigo and i.codigoErro = :codigoErro and i.valorInvalido = :valorInvalido ]
But if i use gradle the same tests just pass fine.
Gradle build however is a bit slower sometimes.
All offending tests inherits from this base test case:
package base;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import base.dbunit.DataSetResolver;
import base.dbunit.DbUnitManager;
import br.com.syspdv.web.Settings;
import br.com.syspdv.web.SettingsFactory;
import mocks.UsuarioLogadoMock;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:applicationContext-principal.xml",
"classpath:applicationContext-properties-test.xml",
"classpath:applicationContext-remoting.xml",
"classpath:applicationContext-remoting-test.xml",
"classpath:applicationContext-jms-test.xml",
"classpath:applicationContext-mocks.xml"
})
@Transactional
public abstract class SpringIntegrationTestCase {
protected String dataset = DataSetResolver.resolve(this.getClass());
@Autowired
protected DbUnitManager dbUnitManager;
@PersistenceContext
protected EntityManager entityManager;
@Autowired
private PlatformTransactionManager txManager;
private boolean erroDataSet = false;
private static boolean clear;
private Settings settings = new SettingsFactory().getInstance();
@BeforeClass
public static void setDefaultUpClass() {
System.setProperty("app.env", "test");
clear = false;
}
@Before
public void setDefaultUp() {
try {
if(!clear) {
if (dataset != null)
dbUnitManager.cleanAndInsert(dataset);
clear = true;
} else {
if (dataset != null)
dbUnitManager.insert(dataset);
}
} catch(IllegalStateException e) {
erroDataSet = true;
throw e;
}
}
@After
public void setDefaultClear() {
if (!erroDataSet && dataset != null)
dbUnitManager.deleteAll(dataset);
erroDataSet = false;
clearReplicacaoFiles();
}
private void clearReplicacaoFiles() {
File file = new File(this.settings.getHomeDir() , ".replicacao");
File[] files = file.listFiles();
if(files != null) {
for(File f: files) {
f.delete();
}
}
}
@AfterClass
public static void clearLoggedUsers(){
UsuarioLogadoMock.deslogar();
}
protected <T> T _doInsideANewTransaction(TransactionCallback<T> action) {
DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionTemplate tx = new TransactionTemplate(txManager, def);
return tx.execute(action);
}
protected Date getData(String value) {
try {
return new SimpleDateFormat("dd/MM/yyyy").parse(value);
} catch (Exception e) {}
return null;
}
protected Date getDataComPattern(String value, String pattern) {
try {
return new SimpleDateFormat(pattern).parse(value);
} catch (Exception e) {}
return null;
}
protected Date getDataComHora(String value) {
try {
return new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(value);
} catch (Exception e) {}
return null;
}
protected String getData(Date data){
return new SimpleDateFormat("dd/MM/yyyy").format(data);
}
protected void flushAndClear(){
entityManager.flush();
entityManager.clear();
}
}
In the print, only the gradle configurations are albe to execute properly, but sometimes they do take too long to execute.
Regular intellij profiles are faster but are failing if SpringJUnit4ClassRunner is used.
Any help is welcome.
IntelliJ IDEA 2019.2.2 (Ultimate Edition)
Build #IU-192.6603.28, built on September 6, 2019
Licensed to Leonardo Silveira
You have a perpetual fallback license for this version
Subscription is active until September 10, 2020
Runtime version: 11.0.3+12-b304.56 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.2.14-200.fc30.x86_64
GC: ParNew, ConcurrentMarkSweep
Memory: 1958M
Cores: 4
Registry:
Non-Bundled Plugins: Lombook Plugin
Please sign in to leave a comment.
Hello, little sample project where the issue is reproduced will be very appreciated. Please clarify how do you map the table the error tells you about, how does HQL query look like?
Thank you