createNativeQuery :: org.hibernate.MappingException: Unknown entity:

0 respostas
java
F

Após ler mais alguns tópicos na internet, acredito que conseguirei refinar a minha pergunta.
Atualmente tento fazer um objeto customizado apenas para receber a consulta de um sitsema legado para tal, preciso executar a query, abaixo informada, que contem uma serie de join. O problema que mesmo colocando alias para os retornos e especificando o tipo que espero, Unidade.class, é apresentada a mensagem de erro(em anexo) informando que a classe é desconhecida.

POJO:

@Entity
public class Unidade implements Serializable{
	
	private static final long serialVersionUID = 1L;
	

	private Long numeroUnidade;
	private String nomeUnidade;
	private Integer numeroCep;
	private Integer numeroCepComplemento;
	private String tipoServico;
	private Integer status;
	private String logradouro;
	private String bairro;
	private String cidade;
	private String uf;
	private Integer statusVinculo; 

   //getter and setters

Atualmente fazendo um select simples retornando apenas um inteiro, como um count, o resultado é apresentado sem maiores problemas:

@PersistenceContext(unitName="projetoAtividade")
private EntityManager em;

public void selectTeste(){
		int quantidade = (Integer) em.createNativeQuery("select count(*) from abc.nattbu29_escritorio;").getSingleResult();
		System.out.println("========== QUANTIDADE DE REGISTRO NA TABELA ===========");
		System.out.println(quantidade);
	}

Query que desejo relacionar com o objeto:

@SuppressWarnings("unchecked")
    	public List<UnidadeTeste> buscarUnidadeGenerica(int numeroCeps, int numeroComplementoCeps){
    		List<UnidadeTeste> lsita = new ArrayList<UnidadeTeste>();
    		String query = "SELECT "
    				+"TBZ21.NATURAL as numeroPv, "
    				+"TBZ21.UNIDADE as nomePv, "
    				+"TBZ21.SITUACAO as statusVinculacao, "
    				+"TBJ55.TPO_ATUACAO_U44 as tipoServAZW, "
    				+"TBJ55.SITUACAO_ATUAL as status, "
    				+"TBH18.LOCALIDADE as cidade, "
    				+"'' as bairro, "
    				+"'' as logradouro, "
    				+"TBH18.CEP as numeroCep, "
    				+"TBH18.CEP_COMPLEMENTO as numeroCepComplemento, "
    				+"TBH18.FK_AZWVWL22_UNISG as uf "
    				+"FROM AZW.AZWTBJ55_RGATUACAO TBJ55 "
    				+"LEFT JOIN AZW.AZWTBH18_LOCALIDADE TBH18 ON "
    				+"TBH18.LOCALIDADEE = TBJ55.LOCALIDADEE "
    				+"LEFT JOIN AZW.AZWTBZ21_UNIDADE TBZ21 ON "
    				+"TBJ55.NATURAL = TBZ21.NATURAL "
    				+"WHERE TBH18.CEP = ?1 "
    					+"AND TBH18.CEP_COMPLEMENTO = ?2; "
    		
    		lsita = em.createNativeQuery(query, Unidade.class)
    				.setParameter(1, numeroCeps)
    				.setParameter(2, numeroComplementoCeps)
    				.getResultList();
    		System.out.println(lsita.size()+"<<<<=====================");
    		return lsita;
    	}

Error:

Caused by: org.hibernate.MappingException: Unknown entity: br.com.project.modelo.UnidadeTeste
	at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1031) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:336) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:377) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:356) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:172) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:87) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.engine.query.spi.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:67) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:155) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.internal.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:218) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:224) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
	at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
	... 84 more

Em minhas pesquisas pela internet, o pessoal simplesmente informa que bastaria colocar @Entity na classe e logo ela já poderia ser utilizada.

Alguém teria alguma ideia do que pode estar acontecendo, em outra palavras, o que eu estou fazendo de errado.

Criado 18 de março de 2016
Respostas 0
Participantes 1