getSessionFactory().getCurrentSession().createQuery(
"from Category where categoryParentId = :parentId").setLong("parentId", parentId).list();
<class name="com.domain.Category" table="Category">
<id name="id" type="long" access="property">
<column name="categoryId" length="20"/>
<generator class="identity"/>
</id>
<property name="name" column="categoryName" type="string"/>
<property name="parentId" column="categoryParentId" type="long"/>
<bag name="children" table="Category" inverse="true" lazy="true" fetch="select">
<key>
<column name="categoryParentId" not-null="true"/>
</key>
<one-to-many class="com.domain.models.Category"/>
</bag>
</class>
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>