1

名前付きクエリが表示されない理由がわかりません。誰かがそれに光を当ててくれることを願っています:
ここにコードがあります:

@Data
@Entity
@Table(name = "shipments")
    @NamedNativeQueries({
        @NamedNativeQuery(name = "byShipmentNumber", query = "select S.SHIPMENTS_ID,S.SHIPMENT_NUMBER,S.COMPANIES_ID, S.COMPANIES_ID_3,(min(sil.IMPORT_PCT)) MIN_PCT,(max(sil.IMPORT_PCT)) MAX_PCT,"
        + "(case when ((nvl((SUM(case when (nvl(SIL.IMPORT_PCT,0)>0) then 1 end)),0)) < count(nvl(SIL.IMPORT_PCT,0))) then 0 else 1 end) Status from SHIPMENTS s "
        + "join shipment_invoices si on s.shipments_id = si.shipments_id"
        + "join SHIPMENT_INVOICE_LINES sil on SI.SHIPMENT_INVOICES_ID = sil.SHIPMENT_INVOICES_ID"
        + "where s.SHIPMENT_NUMBER = :shipmentNumber"
        + "and companies_id=23351763"
        + "group by S.SHIPMENTS_ID,S.SHIPMENT_NUMBER,S.COMPANIES_ID, S.COMPANIES_ID_3;",
        resultClass = Shipments.class)
    })
    public class Shipments implements Serializable {


        @Id
        @Column(name = "shipments_id")
        private Long id;
        @Column(name = "shipment_number")
        private String shipmentNumber;
        @Column(name = "companies_id")
        private String billTo;
        @Column(name = "companies_id_3")
        private String issuer;
        @Column(name = "status")
        private String status;
        @Column(name = "min_pct")
        private String minImportCost;
        @Column(name = "max_pct")
        private String maxImportCost;


        public static List<Shipments> getShipmentByShipmentNumber(Session session, String shipmentNumber) {
            Query query = session.getNamedQuery("byShipmentNumber");
            query = query.setString("shipmentNumber", shipmentNumber);
            return query.list();
        }

ここにエラーがあります:

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/ImportCost.spring] threw exception [Request processing failed; nested exception is org.hibernate.MappingException: Named query not known: byShipmentNumber] with root cause
org.hibernate.MappingException: Named query not known: byShipmentNumber
4

2 に答える 2

0

@Entityクラスに として注釈が付けられていないため、JPAによって無視されているためだと思います。

于 2013-03-19T15:34:58.627 に答える
0

プログラミングエラーではなく、セットアップエラーだったようです。
私の db.xml (春の下) で、間違ったフォルダーをスキャンしていました。

bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="datasource" />
        <property name="packagesToScan" value="**dk.lector.bestinfoII.importcost.domain**" 
....(other properties)....
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:component-scan base-package="**dk.lector.bestinfoII.importcost.domain**"/>

** 間違ったフォルダへのリンクがあったあたり

于 2013-03-20T08:35:28.383 に答える