Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3608988
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:34:12+00:00 2026-05-18T21:34:12+00:00

I am using Hibernate. My database is as follows A Category has many attributes

  • 0

I am using Hibernate. My database is as follows

A Category has many attributes

class category
contains

private Set <Attribute> AllAttributes= new HashSet  <Attribute>();

class attribute

How do I retrieve all categories together with their attributes because I am trying ‘from category’ but it is not working

Category Mapping File:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 8:37:02 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.Models.Category" table="CATEGORY">
        <id name="CategoryId" type="long">
            <column name="CATEGORYID" />
            <generator class="native" />
        </id>
        <property name="CategoryName" type="java.lang.String">
            <column name="CATEGORYNAME" />
        </property>

        <many-to-one name="ParentCategory" class="com.BiddingSystem.Models.Category">
            <column name="PARENT_CATEGORY_ID" />
        </many-to-one>

        <set name="SubCategory" lazy="false" cascade="all-delete-orphan" inverse="true">
            <key>
                <column name="PARENT_CATEGORY_ID" />
            </key>
            <one-to-many class="com.BiddingSystem.Models.Category" />
        </set>

        <set name="AllAttributes" table="ATTRIBUTE" inverse="false" lazy="true"  cascade="all">
            <key>
                <column name="CATEGORYID" />
            </key>
            <one-to-many class="com.BiddingSystem.Models.Attribute" />
        </set>

    </class>
</hibernate-mapping>

Attribute Mapping File:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 5:25:09 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.Models.Attribute" table="ATTRIBUTE">
        <id name="AttributeId" type="long">
            <column name="ATTRIBUTEID" />
            <generator class="native" />
        </id>
        <property name="AttributeName" type="java.lang.String">
            <column name="ATTRIBUTENAME" />
        </property>
        <set name="Options" table="ATTRIBUTEOPTION" inverse="false"  cascade="all">
            <key>
                <column name="ATTRIBUTEID" />
            </key>
            <one-to-many class="com.BiddingSystem.Models.AttributeOption" />
        </set>
    </class>
</hibernate-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:34:12+00:00Added an answer on May 18, 2026 at 9:34 pm

    You have mapped the association with lazy="true". This tells hibernate that by default, a category’s attributes should only be loaded from the database when they are actually accessed, in contrast to lazy="false" which would instruct hibernate to load the attributes whenever it loads a category. However, the directive in the mapping file affects all queries.

    In case you want it only for a particular query, check out
    http://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins :

    A “fetch” join allows associations or
    collections of values to be
    initialized along with their parent
    objects using a single select. This is
    particularly useful in the case of a
    collection. It effectively overrides
    the outer join and lazy declarations
    of the mapping file for associations
    and collections. See Section 20.1,
    “Fetching strategies” for more
    information.

    from Cat as cat
        inner join fetch cat.mate
        left join fetch cat.kittens
    

    A fetch join does not usually need to
    assign an alias, because the
    associated objects should not be used
    in the where clause (or any other
    clause). The associated objects are
    also not returned directly in the
    query results. Instead, they may be
    accessed via the parent object. The
    only reason you might need an alias is
    if you are recursively join fetching a
    further collection:

    from Cat as cat
        inner join fetch cat.mate
        left join fetch cat.kittens child
        left join fetch child.kittens
    

    The fetch construct cannot be used in
    queries called using iterate() (though
    scroll() can be used). Fetch should be
    used together with setMaxResults() or
    setFirstResult(), as these operations
    are based on the result rows which
    usually contain duplicates for eager
    collection fetching, hence, the number
    of rows is not what you would expect.
    Fetch should also not be used together
    with impromptu with condition. It is
    possible to create a cartesian product
    by join fetching more than one
    collection in a query, so take care in
    this case. Join fetching multiple
    collection roles can produce
    unexpected results for bag mappings,
    so user discretion is advised when
    formulating queries in this case.
    Finally, note that full join fetch and
    right join fetch are not meaningful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using NHibernate with Sdf database. In my hibernate.cfg.xml file i've set: <property name=hbm2ddl.auto
I have a bean which I map to the database using Hibernate. I'm using
I am using Hibernate in a Java application to access my Database and it
I'm using Hibernate for ORM of my Java app to an Oracle database (not
I am using hibernate to update 20K products in my database. As of now
I have a database table using an enum. This is already working with hibernate
I'm trying to insert some new objects into a firebird database using NHibernate. I
I have an existing database that I am now connecting to using hibernate. I
i am using hibernate to create entities and database tables and i am confused
I am using a hibernate application to store data in Postgres database I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.