dbenoff wrote:
First result and max results work fine with queries involving joins. Post your mappings and the HQL.
hi
thanks for your reply and please find attached the info for the query and pagination
please let me know if you need more info.
very much appreciated your help
Patria
here are the mappings
FBB_ACCOUNT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.account.FbbAccount" table="FBB_ACCOUNT">
<id column="ACCNT_ID" name="id" type="long">
<generator class="sequence">
<param name="sequence">FBB_ACCNT_PK_SEQ</param>
</generator>
</id>
<property column="NAM_ACCOUNT_ID" length="100" name="namAccountId" not-null="true" type="string"/>
<property column="NAM_CUSTODIAN_ACCOUNT" length="30" name="namCustodianAccount" type="string"/>
<property column="GOAL_ID" length="12" name="goalId" type="long"/>
<property column="MEMBER_ID" length="12" name="memberId" type="long"/>
<property column="MEMBER_NAME" length="250" name="memberName" type="string"/>
<property column="ACTIVE" length="1" name="active" type="string"/>
<property column="CUSTODIAL_ACCOUNT_LMD" length="7" name="custodialAccountLmd" type="timestamp"/>
<property column="COMPLETE_ACCOUNT_OPEN_LMD" length="7" name="completeAccountOpenLmd" type="timestamp"/>
<property column="ACCOUNT_CREATION_COMPLETE" length="1" name="accountCreationComplete" type="string"/>
</class>
<query name="com.sp.fbb.businessobject.account.AccountByGoalId">
from FbbAccount as c where c.goalId = :goalID
</query>
</hibernate-mapping>
FBB_GOAL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.goal.Goal" table="FBB_GOAL" dynamic-insert="true" dynamic-update="true">
<id name="goalID" column="GOAL_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">FBB_GOAL_PK_SEQ</param>
</generator>
</id>
<property column="NAM_GOAL_ID" length="12" name="namGoalID" type="java.lang.Long" />
<property column="HHOLD_ID" length="12" name="householdID" type="java.lang.Long" insert="false" />
<property column="USER_ID" length="12" name="producerID" type="java.lang.Long" />
<property column="GOAL_NAME" name="name" length="30" type="string" not-null="true" />
<property column="GOAL_DESCRIPTION" name="description" length="1024" type="string" />
<property column="GOAL_ACTIVE" name="active" length="1" type="string" />
<property column="GOAL_ISDUMMY" name="dummy" length="1" type="string" />
<property column="TAAM_COMPLETED" name="taamCompleted" type="string" length="1" update="true" insert="false"/>
<property column="GOAL_HH_ACTIVE" name="isLinkedToHH" type="string" length="1" />
<property column="GOAL_HH_LMD" length="7" name="goalHHLinklastModifiedDate" type="timestamp" update="true"/>
<property column="LAST_MODIFIED_DATE" name="lastModifiedDate" type="timestamp" update="false" insert="false"/>
<property column="IMPL_ID" length="1024" name="implementationID" type="java.lang.String"/>
<property column="IMPL_COMMENTS" length="1024" name="implementationComments" type="java.lang.String"/>
<property column="GOALCTGRY_ID" length="12" name="goalCategoryID" not-null="true" type="java.lang.Long"/>
<set name="accounts" table="FBB_ACCOUNT" inverse="true" lazy="true">
<key column="GOAL_ID" />
<one-to-many class="com.sp.fbb.businessobject.account.FbbAccount" />
</set>
</class>
</hibernate-mapping>
FBB_NAM_ALERT_INSTANCE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.alert.AnAlertInstance" table="FBB_NAM_ALERT_INSTANCE">
<id column="ALRTINST_ID" name="alertID" type="long">
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>
<property column="USER_ID" length="12" name="userID" not-null="true" type="java.lang.Long"/>
<property column="ALERT_TEMPLATE_ID" length="12" name="alertTemplateID" type="java.lang.Long"/>
<property column="ALERT_ID" length="12" name="namAlertID" type="java.lang.Long"/>
<property column="MESSAGE" length="1024" name="message" type="string"/>
<property column="CREATED_DATE" length="7" name="createdDate" type="timestamp"/>
<property column="CLIENT_ID" length="12" name="clientID" type="java.lang.Long"/>
<property column="CLIENT_NAME" length="1024" name="clientName" type="string"/>
<property column="ACCOUNT_ID" name="accountID" type="java.lang.Long"/>
<property column="CUSTODIAN_ACCOUNT_NO" length="12" name="custodianAccountNo" type="string"/>
<property column="ACCOUNT_VALUE" length="15" name="accountValue" type="java.lang.Float"/>
<property column="ACCOUNT_VARIANCE" length="5" name="accountVariance" type="java.lang.Float"/>
<property column="VARIANCE_LIMIT" length="5" name="varianceLimit" type="java.lang.Float"/>
<property column="MODEL_NAME" length="250" name="modelName" type="string"/>
<property column="MAP_NAME" length="250" name="mapName" type="string"/>
<property column="BASKET_NAME" length="250" name="basketName" type="string"/>
<property column="TICKER" length="250" name="ticker" type="string"/>
<property column="ALRT_STATUS" length="18" name="alertStatus" type="string"/>
<property column="ALERT_STATUS_CODE_ID" length="1" name="alertStatusCode" type="string"/>
<property column="ALRT_DELETE" length="1" name="alertDelete" type="string"/>
</class>
</hibernate-mapping>
FBB_NAM_ALERT_STATUS_CODE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.alert.AnAlertStatusCode" table="FBB_NAM_ALERT_STATUS_CODE">
<id column="ALERT_STATUS_CODE_ID" name="alertStatusCodeID" type="string">
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>
<property column="ALERT_STATUS_CODE_TEXT" length="250" name="alertStatusCodeText" not-null="false" type="string"/>
</class>
</hibernate-mapping>
FBB_NAM_ALERT_TEMPLATE_CODE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.alert.AnAlertTemplateCode" table="FBB_NAM_ALERT_TEMPLATE_CODE">
<id column="ALERT_TEMPLATE_ID" name="alertTemplateID" type="long">
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>
<property column="ALERT_TEMPLATE_TEXT" length="250" name="alertTemplateText" not-null="false" type="string"/>
</class>
</hibernate-mapping>
code for pagination
Code:
String query=
"SELECT a.modelName,c.alertTemplateText,a.clientName,a.clientID,a.custodianAccountNo,a.accountValue,d.name,a.createdDate,a.message,a.alertStatusCode,a.accountID,d.goalID,a.alertID
FROM AnAlertInstance a,AccountAlertTemplate b,AnAlertTemplateCode c,Goal d, FbbAccount e
WHERE
(a.alertTemplateID=b.namAlertTmplId) and (a.alertTemplateID=c.alertTemplateID) and (b.subscribe='Y') and (a.userID =:userID) and (e.goalId=d.goalID) and (a.namAlertID=:alertID) and (a.accountID=b.accntId) and (a.accountID=e.id)";
transaction = session.beginTransaction();
query =session.createQuery(query);
query.setParameter("userID", userID);
query.setParameter("alertID", alertID
query.setMaxResults(1);
query.setFirstResult(1);
results = query.list();
transaction.commit();