-1

I fire a query for get device object but after fire this HQL query automatically subchild(deviceprofile) details how can i fix using HQL .....


com.zaxxer.hikari.hibernate.HikariConnectionProvider

     <property name="hibernate.hikari.dataSource.url">jdbc:mysql://localhost:3306/gpstracking?autoReconnect=true</property>
        <property name="hibernate.hikari.dataSource.user">root</property>
        <property name="hibernate.hikari.dataSource.password">root</property> 
        <property name="hibernate.hikari.dataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlDataSource</property>
        <property name="hibernate.hikari.maximumPoolSize">50</property>
        <property name="hibernate.hikari.idleTimeout">30000</property> 
        <!--   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/gpstracking?autoReconnect=true</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property> --> 
        <property name="hibernate.use_sql_comments">true</property>

               <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property><!--org.hibernate.dialect.MySQLDialect-->
        <property name="current_session_context_class">thread</property>
        <property name="show_sql">true</property>                   
      <!--  <mapping class="Model.ScheduleAlert" /> -->

        <mapping resource="Model/ScheduleAlert.hbm.xml"/> 

        <mapping resource="Model/login.hbm.xml"/>
        <mapping resource="Model/device.hbm.xml"/>
        <mapping resource="Model/geopath.hbm.xml"/>
        <mapping resource="Model/geopath_detail.hbm.xml"/>
        <mapping resource="Model/DeviceImage.hbm.xml"/>
        <mapping resource="Model/lastTrack.hbm.xml"/>
        <mapping resource="Model/Gt06portrequest.hbm.xml"/>
        <mapping resource="Model/history.hbm.xml"/>
        <mapping resource="Model/historyzero.hbm.xml"/>
        <mapping resource="Model/adminMaster.hbm.xml"/>
        <mapping resource="Model/Message.hbm.xml"/>
        <mapping resource="Model/PortRequests.hbm.xml"/>
        <mapping resource="Model/PortParsers.hbm.xml"/>
        <mapping resource="Model/Hostname.hbm.xml"/>
        <mapping resource="Model/EmailTemplet.hbm.xml"/>
        <mapping resource="Model/SelectedTemp.hbm.xml"/>
        <mapping resource="Model/SancharnetUser.hbm.xml"/>
        <mapping resource="Model/MessageTemplate.hbm.xml"/>
        <mapping resource="Model/SelectedMsgTemp.hbm.xml"/>
        <mapping resource="Model/Fence.hbm.xml"/>
        <mapping resource="Model/FenceDevice.hbm.xml"/>
        <mapping resource="Model/tag.hbm.xml"/>
        <mapping resource="Model/tagtype.hbm.xml"/>
        <mapping resource="Model/AlertMessages.hbm.xml"/>
        <mapping resource="Model/MaxSpeed.hbm.xml"/>
        <mapping resource="Model/alert/Alert.hbm.xml"/>
        <mapping resource="Model/managerSettings.hbm.xml"/>
        <mapping resource="Model/MobileParsers.hbm.xml"/>
        <mapping resource="Model/SampleLivePath.hbm.xml"/>
        <mapping resource="Model/managerMsgSettings.hbm.xml"/>
        <mapping resource="Model/KMLFiles.hbm.xml"/>
        <mapping resource="Model/DemoKmlFiles.hbm.xml"/>
        <mapping resource="Model/DeviceGroup.hbm.xml"/>
        <mapping resource="Model/AnalogData.hbm.xml"/>
        <mapping resource="Model/PoiPoint.hbm.xml"/>
        <mapping resource="Model/deviceprofile.hbm.xml"/>
        <mapping resource="Model/DigitalInputAlert.hbm.xml"/>
        <mapping resource="Model/AnalogInputAlert.hbm.xml"/>
        <mapping resource="Model/POIAlert.hbm.xml"/>
        <mapping resource="Model/OverConsumptionAlert.hbm.xml"/>
        <mapping resource="Model/Devicemaster.hbm.xml"/>
        <mapping resource="Model/analogdigitalparameter.hbm.xml"/>
        <mapping resource="Model/ManagerReportMaster.hbm.xml"/>
        <mapping resource="Model/ManagerReportChild.hbm.xml"/>
        <mapping resource="Model/systemParameter.hbm.xml"/>
        <mapping resource="Model/GeopathAlert.hbm.xml"/>
        <mapping resource="Model/Drivermanage.hbm.xml"/>
        <mapping resource="Model/Drivermaster.hbm.xml"/>
        <mapping resource="Model/Usermaster.hbm.xml"/>
        <mapping resource="Model/Useralocation.hbm.xml"/>
        <mapping resource="Model/Kmllive.hbm.xml"/>
        <mapping resource="Model/Payment.hbm.xml"/>
        <mapping resource="Model/Locationdata.hbm.xml"/>
        <mapping resource="Model/Alertallocationchild.hbm.xml"/>
        <mapping resource="Model/Alertallocationmaster.hbm.xml"/>
        <mapping resource="Model/Expiryreport.hbm.xml"/>
        <mapping resource="Model/Imagedata.hbm.xml"/>
        <mapping resource="Model/Convertedimg.hbm.xml"/>
        <mapping resource="Model/Antitheftalert.hbm.xml"/>
        <mapping resource="Model/OverStayAlert.hbm.xml"/>
        <mapping resource="Model/Reseller.hbm.xml"/>
        <mapping resource="Model/Client.hbm.xml"/>
        <mapping resource="Model/RouteAlert.hbm.xml"/>
        <mapping resource="Model/RouteMaster.hbm.xml"/>     
         <mapping resource="Model/Onediractionfencealert.hbm.xml"/>       
        <mapping resource="Model/LoginLog.hbm.xml"/>        
        <mapping resource="Model/MaintainanceMaster.hbm.xml"/>        
        <mapping resource="Model/MaintainanceType.hbm.xml"/>        
        <mapping resource="Model/BusScheduleMaster.hbm.xml"/>      
        <mapping resource="Model/Tcpcommand.hbm.xml"/> 
    </session-factory>
</hibernate-configuration>

device.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class lazy="false" name="Model.device" table="devicemaster">
        <!--<cache usage="read-write"/>-->
    <id name="deviceid" type="java.lang.Integer">
      <column name="deviceid"/>
      <generator class="increment"/>
    </id>
    <property index="idx_device_managerid" name="managerId" type="java.lang.Integer">
      <column name="managerId"/>
    </property>
    <property name="tcpudpformat" type="java.lang.String">
      <column length="50" name="tcpudpformat"/>
    </property>
    <property index="idx_device_devicename" name="deviceName" type="java.lang.String">
      <column length="15" name="deviceName"/>
    </property>
    <property name="devicedescription" type="java.lang.String">
      <column length="15" name="devicedescription"/>
    </property>
    <property name="flagcondition" type="java.lang.Boolean">
      <column name="flagcondition"/>
    </property>
    <property index="idx_device_imei" name="imei" type="java.lang.String">
      <column length="15" name="imei"/>
    </property>
    <property name="deviceType" type="java.lang.String">
      <column length="15" name="deviceType"/>
    </property>
    <property name="mobileNo" type="java.lang.String">
      <column length="15" name="MobileNo"/>
    </property>
    <property name="gpsFormate" type="java.lang.String">
      <column length="50" name="GpsFormate"/>
    </property>
    <property name="anglePrecision" type="java.lang.Double">
      <column default="0.0" name="anglePrecision"/>
    </property>
    <property name="preDist" type="java.lang.String">
      <column length="15" name="PreDist"/>
    </property>
    <property name="preTime" type="java.lang.String">
      <column length="15" name="PreTime"/>
    </property>
    <property name="viewDist" type="java.lang.String">
      <column length="15" name="viewDist"/>
    </property>
    <property name="viewTime" type="java.lang.String">
      <column length="15" name="viewTime"/>
    </property>
    <property name="driverMobileNo" type="java.lang.String">
      <column name="driverMobileNo"/>
    </property>
    <property name="driverName" type="java.lang.String">
      <column name="driverName"/>
    </property>
    <property name="milage" type="java.lang.Integer">
      <column length="10" name="milage"/>
    </property>
    <property name="devicemodel" type="string">
      <column length="15" name="devicemodel"/>
    </property>
       <property name="addedon" type="java.util.Date">
      <column name="addedon"/>
    </property>
    <many-to-one column="profileId" index="idx_device_profileid" lazy="false" fetch="join" name="deviceProfile" update="true"/>
    <many-to-one class="Model.DeviceGroup" column="groupno" index="idx_device_groupno" fetch="join" name="devicegroup"  lazy="false"/>
  </class>
</hibernate-mapping>

deviceprofile.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class lazy="false" name="Model.DeviceProfile" table="deviceprofile">
    <id column="ProfileId" name="profileId" type="java.lang.Integer">
      <generator class="increment"/>
    </id>
    <property column="ProfileName" index="idx_deviceprofile_profilename" length="50" name="profileName" type="java.lang.String">
        </property>
    <property column="SystemDate" length="30" name="systemDate" type="java.util.Date">
        </property>
    <property column="Odometer" length="15" name="odometer" type="java.lang.String">
        </property>
    <property column="digital_1" length="15" name="digital1" type="java.lang.String">
        </property>
    <property column="digital_1_inverse" name="digital1_inverse" type="java.lang.Boolean">
        </property>
    <property column="digital_2" length="15" name="digital2" type="java.lang.String">
        </property>
    <property column="digital_2_inverse" name="digital2_inverse" type="java.lang.Boolean">
        </property>
    <property column="digital_3" length="15" name="digital3" type="java.lang.String">
        </property>
    <property column="digital_3_inverse" name="digital3_inverse" type="java.lang.Boolean">
        </property>
    <property column="digital_4" length="15" name="digital4" type="java.lang.String">
        </property>
    <property column="digital_4_inverse" name="digital4_inverse" type="java.lang.Boolean">
        </property>
    <property column="digital_5" length="15" name="digital5" type="java.lang.String">
        </property>
    <property column="digital_5_inverse" name="digital5_inverse" type="java.lang.Boolean">
        </property>
    <property column="analog_5" length="15" name="analog5" type="java.lang.String">
        </property>
    <property column="analog_1_unit" length="15" name="analog1_unit" type="java.lang.String">
        </property>
    <property column="analog_2_unit" length="15" name="analog2_unit" type="java.lang.String">
        </property>
    <property column="analog_3_unit" length="15" name="analog3_unit" type="java.lang.String">
        </property>
    <property column="analog_4_unit" length="15" name="analog4_unit" type="java.lang.String">
        </property>
    <property column="analog_5_unit" length="15" name="analog5_unit" type="java.lang.String">
        </property>
    <property column="analog_1_formula" length="25" name="analog1_formula" type="java.lang.String">
        </property>
    <property column="analog_2_formula" length="25" name="analog2_formula" type="java.lang.String">
        </property>
    <property column="analog_3_formula" length="25" name="analog3_formula" type="java.lang.String">
        </property>
    <property column="analog_4_formula" length="25" name="analog4_formula" type="java.lang.String">
        </property>
    <property column="analog_5_formula" length="25" name="analog5_formula" type="java.lang.String">
        </property>
    <property column="GPSFormat" length="15" name="gpsformat" type="java.lang.String">
        </property>
    <property column="Cummulative_Odometer" length="15" name="cummulativeOdometer" type="java.lang.String">
       </property>
    <set cascade="all" inverse="true" name="analogdatas">
      <key column="profileId"/>
      <one-to-many class="Model.Analogdata"/>
    </set>
    <set cascade="all" inverse="true" lazy="false" name="deviceMaster">
      <key column="profileId"/>
      <one-to-many class="Model.device"/>
    </set>
    <many-to-one cascade="all" column="ManagerId" name="managerSettings2" update="false">
     </many-to-one>
  </class>
</hibernate-mapping>

i have already done this project and DAO file so please provide solution.....

Framester
  • 33,341
  • 51
  • 130
  • 192
  • Please clarify you problem (what do you want to do) and provide a minimal example, no one wants to read a wall of text just to answer. – Bob Brinks Aug 09 '16 at 07:44
  • I really don't understand the question. Can you clarify? – Takarii Aug 09 '16 at 07:56
  • there is many to one relationship between device and deviceprofile If i fire one query like, session.createQuery("from device where deviceid="+deviceId).list(); so, after fire this query 51 time fire other query for his subchild deviceprofile. – samir vora Aug 09 '16 at 09:02
  • You should not use concatenation in any sql string, use http://stackoverflow.com/questions/23008926/how-to-use-prepared-statement-in-jpa instead. And please add entityes etc to your question. – Hash Aug 09 '16 at 09:58

1 Answers1

0

Please explain your question properly. Change deviceprofile.hbm.xml many-to-one mapping as below and check if it help:

<many-to-one cascade="all" column="ManagerId" name="managerSettings2" update="false" lazy="true" fetch="select">
Prabhat Kumar
  • 256
  • 2
  • 9