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 1020095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:06:51+00:00 2026-05-16T11:06:51+00:00

I have these 2 mappings: <hibernate-mapping> <class name=sample.Operator table=OPERATOR> <id name=id > <generator class=native

  • 0

I have these 2 mappings:

<hibernate-mapping>
    <class name="sample.Operator" table="OPERATOR">
        <id name="id" >
            <generator class="native" />
        </id>
        <property name="name"  not-null="true">
            <column name="NAME" />
        </property>
        <set name="pointCodes" inverse="false" lazy="true" cascade="save-update">
            <key>
                <column name="OperatorID" />
            </key>
            <one-to-many class="sample.PointCode" />
        </set>
    </class>

<hibernate-mapping>
 <class name="sample.PointCode" table="POINTCODE">
  <id name="id">
   <generator class="native" />
  </id>
  <properties name="pointCodeKey" unique="true">
   <property name="pointCode" not-null="true">
   </property>
   <property name="networkIndicator" not-null="true">
   </property>
  </properties>
  <property name="name" not-null="true">
  </property>
 </class>
  </hibernate-mapping>

Most of the time when featching an Operator I want the pointCodes to be fetched lazily, so I don’t want to set lazy=”false” in the mappings,

However I have one query, e.g. session.createQuery("from Operator").list() where I do want the pointCodes association to NOT be fetched lazily – how do I do that ?

  • 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-16T11:06:52+00:00Added an answer on May 16, 2026 at 11:06 am

    The hibernate reference manual writes:

    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 have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>
I have these simplified types: public class DataBean extends ZZZZZ { public String name;
I have two domain models: class Resource{ String name static mapping = { sort
I keep getting this error: Error saving identity in IdentityDaoImpl. Reason: org.hibernate.PropertyValueException: not-null property
I have these objects: public class Class { public Guid Id {get;set;} public string
On the database, I have these two tables: - Destination: - idDestination - name
I'm thinking about table layout for a Hibernate-managed class hierarchy, and certainly the table
I currently have the following named query that wraps around a stored procedure:- <hibernate-mapping>
I have a problem with my hibernate mapping using EmbeddedId. My code looks like
I have web project based on Hibernate and Spring (programmatic configuration). The Hibernate mappings

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.