Hibernate查询不返回任何内容,尽管表上存在行



我已经在我的项目中创建了这个新实体,并使用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文件,发现我没有用映射的资源标记映射实体。。这会是问题所在吗?

最新更新