簡體   English   中英

Hibernate 查詢不返回任何內容,盡管表上存在行

[英]Hibernate Query not returning anything, despite rows being present on the table

我已經在我的項目中創建了這個新實體,並使用 hibernate.hbm.xml 文件對其進行了映射,但是盡管表中存在行,但查詢從不返回任何內容。 我在部署期間沒有收到任何錯誤,所以我認為映射是正確的,但我不明白為什么它從不返回任何東西。

這是我的代碼:實體(getter 和 setter 存在,我只是為了簡潔沒有添加它們)

 package com.rmm.lpo.be.data.model.po;

import java.util.Date;

public class ManageIotRequest implements java.io.Serializable, com.enel.framework.be.data.model.po.PersistentObject{
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private Long id;
    private Long lotCode;
    private String transformerCode;
    private String creatorUserId;
    private Boolean pushLpDataRequired;
    private String deviceSelectionMode;
    private String fileName;
    private String fileType;
    private Boolean flDiscarded;
    private Date completionDate;
    private String errorCode;
    private String detailedErrorCode;
    private Date creationDate;
    private Date pDate; ```

HBM 映射

    <?xml version="1.0"?>

<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN">

<!-- Generated 24 nov 2021, 17:10:37 by Hibernate Tools 3.4.0.CR1 -->

-<hibernate-mapping>


-<class dynamic-insert="true" dynamic-update="true" schema="LPO" table="MANAGE_IOT_REQUEST" name="com.rmm.lpo.be.data.model.po.ManageIotRequest">

<meta inherit="false" attribute="implements">com.enel.framework.be.data.model.po.PersistentObject</meta>

<comment>User request for changing Iot desired configuration</comment>


-<id name="id" type="java.lang.Long">

<column name="ID"/>


-<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">

<param name="optimizer">none</param>

<param name="sequence_name">SQ_LPO_ID</param>

<param name="increment_size">1</param>

</generator>

</id>


-<property name="lotCode" type="java.lang.Long">


-<column name="LOT_CODE" not-null="true" scale="0" precision="12">

<comment>Identification of the Lot</comment>

</column>

</property>


-<property name="transformerCode" type="string">


-<column name="TRANSFORMER_CODE" length="64">

<comment>Identification of the Transformer</comment>

</column>

</property>


-<property name="creatorUserId" type="string">


-<column name="CREATOR_USER_ID" length="16">

<comment>Identification of the user creator</comment>

</column>

</property>


-<property name="pushLpDataRequired" type="java.lang.Boolean">


-<column name="PUSH_LP_DATA_REQUIRED">

<comment>Number that identify the acquisition type. 1 = PUSH, 0 =PULL</comment>

</column>

</property>


-<property name="deviceSelectionMode" type="string">


-<column name="DEVICE_SELECTION_MODE" length="16">

<comment>String that identify the device selection mode</comment>

</column>

</property>


-<property name="fileName" type="string">


-<column name="FILE_NAME" length="256">

<comment>Name of the file that is used for the request</comment>

</column>

</property>


-<property name="fileType" type="string">


-<column name="FILE_TYPE" length="16">

<comment>Type of data contained in the file used for deviceselection</comment>

</column>

</property>


-<property name="flDiscarded" type="java.lang.Boolean">


-<column name="FL_DISCARDED">

<comment>1 = discarded request, 0 = executed request</comment>

</column>

</property>


-<property name="errorCode" type="string">


-<column name="ERROR_CODE" length="16">

<comment>String for technical errors</comment>

</column>

</property>


-<property name="detailedErrorCode" type="string">


-<column name="DETAILED_ERROR_CODE" length="16">

<comment>String for technical errors</comment>

</column>

</property>


-<property name="completionDate" type="java.util.Date">


-<column name="COMPLETION_DATE">

<comment>date/time of creation of the LPO</comment>

</column>

</property>


-<property name="creationDate" type="java.util.Date">


-<column name="CREATION_DATE" not-null="true">

<comment>date/time of creation of the LPO</comment>

</column>

</property>


-<property name="pDate" type="java.util.Date">


-<column name="PDATE" not-null="true">

<comment>PDATE</comment>

</column>

</property>

</class>

</hibernate-mapping> 

這是我的 DAO:

package com.rmm.lpo.be.data.dao;



@Named("manageIotRequestDao")
public class ManageIotRequestDaoImpl extends TwoBeatBaseHibernateCrudDao<ManageIotRequest, Long>
        implements ManageIotRequestDao {
    private ManageIotRequestPOConverter manageIotRequestPOConverter;
    
    private static final String LOT_SEQUENCE = "SQ_MANAGE_IOT_REQUEST_LOT_CODE";

    
    
    @Inject
    public ManageIotRequestDaoImpl(
            @Named("manageIotRequestPOConverter") ManageIotRequestPOConverter manageIotRequestPOConverter) {
        this.manageIotRequestPOConverter = manageIotRequestPOConverter;
    }
@Override
    public List<ManageIotRequestBO> getIotRequestByLotCode(Long lotCode) throws DaoException {

        List<ManageIotRequestBO> result = new ArrayList<ManageIotRequestBO>();
        try {
            logger.debug("getIotRequestByLotId starts with input: lotCode = {}", lotCode);


            
            Query query=sessionFactory.getCurrentSession().createQuery("select m from com.enel.twobeat.rmm.lpo.be.data.model.po.ManageIotRequest m where m.lotCode = :lotCode");    
            query.setParameter("lotCode", lotCode);
            List<ManageIotRequest> listPo = query.list();
            if (listPo != null) {
                for (ManageIotRequest po : listPo) {
                    ManageIotRequestBO bo = (ManageIotRequestBO) manageIotRequestPOConverter.convertPOtoBO(po);
                    result.add(bo);
                }
            }
            
            logger.debug("getIotRequestByLotId ends with result = {}", result);
        } catch (HibernateException | ConverterException e) {
            throw new DaoException(e.getMessage(), e);
        }
        return result;

    }
} 

我究竟做錯了什么? 我還運行了一個沒有 where 條件的查詢,只是一個簡單的 select 星,但它仍然沒有返回任何內容。

我檢查了我的 hibernate.cfg.xml 文件,我發現我沒有用映射資源標簽映射那里的實體..這可能是問題嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM