2016-03-23 16 views
0

Bir dizi faydalı hesaplamayı gerçekleştiren bir veritabanı görünümünden kayıt seçmek istiyorum.Ters mühendislik uygulanmış görünümlü QuerySyntaxException

<table-filter match-name="v_candidate" /> 

<table name="v_candidate"> 
    <primary-key> 
     <key-column name="id"/> 
    </primary-key> 
</table> 

tersine mühendislik bu VCandidate.hbm.xml dosyayı oluşturuyor:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 
<!-- Generated Mar 23, 2016 12:12:19 PM by Hibernate Tools 4.3.1.Final --> 
<hibernate-mapping> 
    <class name="db.VCandidate" table="v_candidate" optimistic-lock="version"> 
     <id name="id" type="java.lang.Integer"> 
      <column name="id" /> 
      <generator class="assigned" /> 
     </id> 
     <property name="outflowElevation" type="big_decimal"> 
      <column name="outflow_elevation" precision="131089" scale="0" /> 
     </property> 
     <property name="name" type="string"> 
      <column name="name" /> 
     </property> 
     <property name="floodedVolume" type="java.lang.Double"> 
      <column name="flooded_volume" precision="17" scale="17" /> 
     </property> 
     <property name="servedArea" type="big_decimal"> 
      <column name="served_area" precision="131089" scale="0" /> 
     </property> 
    </class> 
</hibernate-mapping> 

Ve aşağıdaki VCandidate sınıf: o zaman

package db; 
// Generated Mar 23, 2016 12:12:19 PM by Hibernate Tools 4.3.1.Final 

import java.io.Serializable; 
import java.math.BigDecimal; 

/** 
* VCandidate generated by hbm2java 
*/ 
public class VCandidate implements java.io.Serializable { 

    private Integer id; 
    private BigDecimal outflowElevation; 
    private String name; 
    private Double floodedVolume; 
    private BigDecimal servedArea; 

    public VCandidate() { 
    } 

    public VCandidate(Integer id) { 
     this.id = id; 
    } 

    public VCandidate(Integer id, BigDecimal outflowElevation, String name, Double floodedVolume, BigDecimal servedArea) { 
     this.id = id; 
     this.outflowElevation = outflowElevation; 
     this.name = name; 
     this.floodedVolume = floodedVolume; 
     this.servedArea = servedArea; 
    } 

    public Integer getId() { 
     return this.id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    public BigDecimal getOutflowElevation() { 
     return this.outflowElevation; 
    } 

    public void setOutflowElevation(BigDecimal outflowElevation) { 
     this.outflowElevation = outflowElevation; 
    } 

    public String getName() { 
     return this.name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public Double getFloodedVolume() { 
     return this.floodedVolume; 
    } 

    public void setFloodedVolume(Double floodedVolume) { 
     this.floodedVolume = floodedVolume; 
    } 

    public BigDecimal getServedArea() { 
     return this.servedArea; 
    } 

    public void setServedArea(BigDecimal servedArea) { 
     this.servedArea = servedArea; 
    } 
} 

ben .reveg.xml dosyasına aşağıdaki parçaları ekleyerek başlayın Bu görünümden erişilebilen kayıtları almaya çalışın:

Bu görünüm için oluşturulan

Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: VCandidate is not mapped [from VCandidate] 
    at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) 
    at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) 
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) 
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) 
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) 
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) 
    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) 
    at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1894) 
    at opt.Main.plotData(Main.java:66) 
    at opt.Main.main(Main.java:90) 
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: VCandidate is not mapped 
    at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171) 
    at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91) 
    at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:76) 
    at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3701) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3590) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:716) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:572) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:309) 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:257) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) 
    ... 9 more 

.hbm.xml ve .java dosyaları hemen hemen tablolar için üretilenler gibi aynı yolu takip: derhal tanıdık istisna ile sonuçlanır

Query query = session.createQuery("from VCandidate"); 

. Ancak tablolar ile kayıt almada sorun yaşıyorum.

Neyi eksik?

cevap

0

HQL kullanmak yerine bir yerel sorgu kullanarak çalıştım. Öyleyse:

Query query = session.createSQLQuery(
    "select * from v_candidate") 
    .addEntity(VCandidate.class); 
List<VCandidate> candidates = query.list(); 

Bu, başka bir şeyden daha çok bir çözümdür, ancak şimdilik bu iş güzeldir.

İlgili konular