Trabajando en una aplicación que por azares del destino está con varias tecnologías de persistencia, entre algunos sabores: JDBC, Hibernate y ultimamente JPA, no me pregunten porqué, pero se tienen dos lugares donde se crean Entities, uno legado y otro donde se quiere unificar y poner orden.
Una de las tareas fue migrar un Entity para que poco a poco se vayan teniendo en un sólo lugar dentro de la Nueva estructura, sin embargo al ejecutar la aplicación lanzaba este problema:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: andres is not mapped [SELECT CC FROM andres CC WHERE CC.gubernamentales=:guber AND CC.mercado=:mercado]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1364)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:309)
at asar.analitics.db.hibernate.dao.impl.CalifConsarDAOImpl.getAllInstrumentoNoGubernamental(CalifConsarDAOImpl.java:232)
at asar.analitics.service.impl.CalifConsarServiceImpl.getAllCalifConsarNoGubernamental(CalifConsarServiceImpl.java:50)
at asar.analitics.vista.regimen.EsperanzaPerdidaScroolPane.calculaEsperanzaPerdida(EsperanzaPerdidaScroolPane.java:201)
at asar.analitics.vista.regimen.EsperanzaPerdidaScroolPane.calculateAll(EsperanzaPerdidaScroolPane.java:169)
at asar.analitics.vista.regimen.EsperanzaPerdidaScroolPane.getTablaEsperanzaPerdida(EsperanzaPerdidaScroolPane.java:323)
at asar.analitics.Regimen.initComponents(Regimen.java:20911)
at asar.analitics.Regimen.(Regimen.java:672)
at asar.analitics.Menu$105.actionPerformed(Menu.java:1811)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: andres is not mapped [SELECT CC FROM andres CC WHERE CC.gubernamentales=:guber AND CC.mercado=:mercado]
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3291)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3180)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:301)
... 44 more
La solución fue poner en el persistence XML las siguientes lineas:
org.hibernate.ejb.HibernatePersistence
entities.CalifConsarEnt
entities.CalifEmisorEnt
entities.CatGruposEmisorEnt
Puesto que las entidades van anotadas, las lineas
entities.CalifConsarEnt, hacen que el EntityManager reconozca la ubicación de la nuevas clases, pues de manera automática no sabe donde encontrarlas.
@Entity
@Table(name="CALIF_CONSAR")
public class CalifConsarEnt {
@Id
@Column(name="INSTRUMENTO")
.
.
.
Espero que la solución le sirva.
Cortesía de Vianey Reyes
@VianeyItzayana