2017-08-21 114 views
0

我,在Hibernate和Tomcat 8.Hibernate映射問題Tomcat8

當我部署應用程序(通過經理/ HTML或創建一個新的文件夾,並把整個項目)沒有問題,但映射問題如果我嘗試把階級到另一個現有應用程序的WEB-INF並運行它,日誌說:

org.hibernate.hql.internal.ast.QuerySyntaxException: Telefonos is not mapped [FROM Telefonos where canal = :canal and (fechaTomado is null or (fechaTomado + 90) >= getdate())] 
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96) 
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120) 
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234) 
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) 
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) 
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) 
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) 
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) 
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) 
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796) 
at operaciones.telefonoscvts.ManejadorTelefonos.listTelefonos(ManejadorTelefonos.java:133) 
at org.apache.jsp.comercial.comercial.ajax.traeNumero_jsp._jspService(traeNumero_jsp.java:123) 
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) 
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) 
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Telefonos is not mapped 

Teléfonos實體

package operaciones.telefonoscvts.dao; 

import java.io.Serializable; 
import javax.persistence.*; 

@Entity 
@Table(name = "telefonos_cvts") 
public class Telefonos implements Serializable { 

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
@Column(name = "id") 
private int id; 

@Column(name = "telefono") 
private String telefono; 

@Column(name = "modalidad") 
private String modalidad; 

@Column(name = "canal") 
private String canal; 

@Column(name = "fechaCarga") 
private String fechaCarga; 

@Column(name = "fechaTomado") 
private String fechaTomado; 

public Telefonos() { 
} 

//get and set methods 

我試過很多方法使它工作,包都很好,它讀取hibernate.cfg.xml,我不知道爲什麼它的應用程序正在失去它的映射。安妮的幫助表示讚賞。

休眠:4.3

謝謝!!

+2

向我們展示Telefonos實體的映射 –

+0

@NikolasCharalambidis,已更新! – Zttan

+0

*但如果我嘗試將這些類放入另一個現有應用程序的WEB-INF中並運行它*,但是您如何完全做到這一點?向我們展示項目層次結構。 –

回答

0

我看到你的映射是正確的。最有可能的解決方案是檢查你是否已經包括休眠實體配置:

@Bean 
public LocalSessionFactoryBean sessionFactory() { 
    LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean(); 
    lsfb.setDataSource(this.dataSource()); 
    lsfb.setPackagesToScan(new String[] { 
     "operaciones.telefonoscvts.dao" 
    }); 
    lsfb.setHibernateProperties(this.hibernateProperties()); 
    return sessionFactory; 
} 

可以實現使用基於XML的配置相同的效果。不過,在這種情況下,我發現註釋更好。

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" > 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan"> 
     <list> 
      <value>operaciones.telefonoscvts.dao</value> 
     </list> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
      <prop key="hibernate.show_sql">${hibernate.show_sql:false}</prop> 
      <prop key="hibernate.format_sql">${hibernate.format_sql:false}</prop> 
     </props> 
    </property>  
</bean> 

來源:Websystique

此外,我建議你多文件Telefonos.java到包operaciones.telefonoscvts.entity(或model)分開負責與數據庫通信的類。