简体   繁体   中英

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

I have created this new entity on my project, and mapped it by using an hibernate.hbm.xml file, but the query never returns anything despite rows being present inside the Table. I get no errors during deploy, so i think the mapping is correct, but i don't understand why it never returns anything.

This is my code: Entity(the getters and setters are present, i just didn't add them for brevity)

 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 MAPPING

    <?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> 

and this is my 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;

    }
} 

What am i doing wrong? I've also ran a query with no where conditions, just a simple select star, but it still returns nothing.

I checked my hibernate.cfg.xml file, and i found out that i hadn't mapped the entity there with the mapped-resource tag..could this be the problem?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM