whitesox12
Programmer
Hi,
I am pretty new to Hibernate and needs some help in resolving the following issue. I am trying to retrieve Menu and SubMenus data from
Database tables. I have two tables Hiber_PARENT_MENU and Hiber_CHILD_MENU. How can I keep the order of my detail records i.e. Sub Menus .Right now everytime I refresh the page Sub Menus order keeps changing. Following are the hbm.xml files.
Here is the code that gets the data:
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
Any help is appreciated. Thanks
I am pretty new to Hibernate and needs some help in resolving the following issue. I am trying to retrieve Menu and SubMenus data from
Database tables. I have two tables Hiber_PARENT_MENU and Hiber_CHILD_MENU. How can I keep the order of my detail records i.e. Sub Menus .Right now everytime I refresh the page Sub Menus order keeps changing. Following are the hbm.xml files.
Code:
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""[URL unfurl="true"]http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">[/URL]
<hibernate-mapping>
<class name="HiberSubMenu" table="Hiber_CHILD_MENU">
<id name="id" column="SUB_MENU_ID" type="long">
<generator class="sequence">
<param name="sequence">Hiber_SUB_MENU_SEQ</param>
</generator>
</id>
<many-to-one name="HiberMenu" class="HiberMenu">
<column name="MENU_ID"/>
</many-to-one>
<property name="subMenuTitle" type="string" length="50" column="SUB_MENU_TITLE"/>
<property name="subMenuUrl" type="string" length="250" column="SUB_MENU_URL"/>
<property name="subMenuActive" type="string" length="1" column="SUB_MENU_ACTIVE"/>
<property name="createdDate" type="timestamp" column="CREATED_DATE"/>
<property name="createdBy" type="string" length="35" column="CREATED_BY"/>
</class>
</hibernate-mapping>
------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""[URL unfurl="true"]http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">[/URL]
<hibernate-mapping>
<class name="HiberMenu" table="Hiber_PARENT_MENU">
<id name="id" column="MENU_ID" type="long">
<generator class="sequence">
<param name="sequence">Hiber_MENU_SEQ</param>
</generator>
</id>
<property name="menuTitle" type="string" length="50" column="MENU_TITLE" not-null="true"/>
<property name="menuUrl" type="string" length="250" column="MENU_URL" not-null="true"/>
<property name="menuActive" type="string" length="1" column="MENU_ACTIVE" not-null="true"/>
<property name="subMenuFlag" type="string" length="1" column="SUB_MENU_FLAG" not-null="true"/>
<property name="createdDate" type="timestamp" column="CREATED_DATE" not-null="true"/>
<property name="createdBy" type="string" length="35" column="CREATED_BY" not-null="true"/>
<set name="subMenu" inverse="true" cascade="all">
<key>
<column name="MENU_ID"/>
</key>
<one-to-many class="HiberSubMenu"/>
</set>
</class>
</hibernate-mapping>
Here is the code that gets the data:
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
Code:
List result = session.createQuery("from HiberMenu as hibermenu where hibermenu.menuHolder = 'Genaral'").list();
Any help is appreciated. Thanks