繁体   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