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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:51:22+00:00 2026-06-01T16:51:22+00:00

I have a class and 2 many-to-one mappings in it , How can I

  • 0

I have a class and 2 many-to-one mappings in it , How can I lazy load them

My properties

**teneo.mapping.also_map_as_class=true
teneo.mapping.set_proxy=true
teneo.mapping.mapping_file_name=/lazy.hbm.xml**

Mapping file ( lazy.hbm.xml)

<class name="EnvironmentImpl" entity-name="**Environment**" abstract="false" lazy="true" discriminator-value="Environment" table="`ENVIRONMENT`" proxy="Environment">
    <meta attribute="eclassName">Environment</meta>

    <property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
        <column not-null="true" unique="false" name="`NAME`"/>
    </property>

    <property name="description" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
        <column not-null="false" unique="false" name="`DESCRIPTION`" length="512"/>
    </property>

    <property name="contact" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
        <column not-null="false" unique="false" name="`CONTACT`"/>
    </property>

    <many-to-one  name="rootAppFolder" entity-name="ApplicationFolder" lazy="proxy" cascade="all" foreign-key="ENVIRONMENT_ROOTAPPFOLDER" insert="true" update="true" not-null="false" unique="true">
        <column not-null="false" unique="false" name="`APPLICATINFLDER_RTAPPFOLDER_ID`"/>
    </many-to-one>

    <many-to-one name="serviceVirtualization" entity-name="ServiceVirtualization" lazy="proxy" cascade="all" foreign-key="ENVIRNMENT_SERVICEVIRTALIZATIN" insert="true" update="true" not-null="false">
        <column not-null="false" unique="false" name="`SRVCVRTLZTN_SRVICVIRTLIZTIN_ID`"/>
    </many-to-one>
</class>

As you can see class Environment has 2 many-to-one's with names ApplicationFolder and serviceVirtualization.

for a HQL query like -  from Environment where name = :name


    Which internally triggers 3 queries  
    Query1 : Environment ( this is right)

    Query2 : ApplicationFolder ( wrong.lazy loading should not.)

    Query 3 : serviceVirtualization ( wrong.lazy loading should not.)



            DEBUG - select environmen0_."NAME" as NAME4_31_, environmen0_."DESCRIPTION" as DESCRIPT5_31_, environmen0_."CONTACT" as CONTACT6_31_, environmen0_."APPLICATINFLDER_RTAPPFOLDER_ID" as APPLICAT7_31_, environmen0_."SRVCVRTLZTN_SRVICVIRTLIZTIN_ID" as SRVCVRTL8_31_ from "ENVIRONMENT" environmen0_ where environmen0_."NAME"=?

            DEBUG - select applicatio0_.e_id as e1_43_0_, applicatio0_.version_ as version3_43_0_, applicatio0_."NAME" as NAME4_43_0_, applicatio0_."ENVIRONMENT_ENV_E_ID" as ENVIRONM5_43_0_ as APPLICAT8_43_0_ from "APPLICATIONFOLDER" applicatio0_ where applicatio0_.e_id=?

            DEBUG - select servicevir0_.e_id as e1_35_0_, servicevir0_.version_ as version3_35_0_, servicevir0_.econtainer_class as econtainer4_35_0_, servicevir0_.e_container as e5_35_0_, servicevir0_.e_container_featureid as e6_35_0_ from "SERVICEVIRTUALIZATION" servicevir0_ where servicevir0_.e_id=?

What approaches I tried so far
1) set lazy=”no-proxy” , dont see any change in number of queries.

2) setting not-found=”exception”.

3)outer-join = “auto”

Can any one suggest me a solution to reduce those 2 extra queries getting fired because of the eager many-to-one relations ?

Please take a note of the foreign key relationships on many-to-one.

  • 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-06-01T16:51:23+00:00Added an answer on June 1, 2026 at 4:51 pm

    lazy is true by default. try getting rid of lazy="proxy".

    reasons for lazy not working:

    • when the referenced type can not be proxied because there is no default constructor or final methods
    • the referenced type is mapped with <class lazy="false"
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a recursive one-to-many relationship that has the default lazy value of true.
I have a Hibernate entity which has one or more <many-to-one mappings, e.g. <hibernate-mapping>
I have a JPA entity class (one of many) and I can run JPQL
I have only one class with many instances. Every instance is observer of couple
I have one abstract class and many child classes. In child classes are from
I have a Employee class with many attributes. One of the attributes is employeeId
I've got a class with many string arrays. I'd like to have one generic
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have a class with many methods. How can I modify my methods so
I have two entities, Job and Language , in a many-to-one relationship. The mapping

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.