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

  • Home
  • SEARCH
  • 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 8792709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:01:03+00:00 2026-06-13T23:01:03+00:00

I got an Entity 1 -> SubEntity n One-To-Many-relation. I just would like to

  • 0

I got an Entity 1 -> SubEntity n One-To-Many-relation.

I just would like to check, if this is the most efficient way to search for an Entity, including a specified SubEntity in its “One-To-Many-Collection”. It works, but do I have to join fetch the SubEntities or is there a more lightweight solution if I don’t need all SubEntities to be loaded? (FetchMode = Lazy)

public Entity getEntityBySubEntity(SubEntity subEntity) { 
     List<Entity> result = (List<Entity>)getHibernateTemplate.findByNamedParam(
         "From Entity as e left join fetch e.subEntities as sub where sub.id = :id","id",subEntity.getId()); 
     if (!result.isEmpty()) { 
          return result.get(0);
     } else {
          throw new NoResultException();
     }
 }

(by the way, there should always be just one result…)

thx in adv,

cav

  • 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-13T23:01:04+00:00Added an answer on June 13, 2026 at 11:01 pm

    Your query is fine, but needlessly fetches the subEntities. Just remove the fetch keyword. And since the sub-entity can’t be null to satisfy the condition, an inner join is OK:

    select e from Entity e inner join e.subEntities sub where sub.id = :id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

weirdly I cannot find something simple about this, I've got 2 entity, one inside
imagine I got an entity: MyEntity { ... Nullable<Int64> MyProperty ... } I would
I got a Entity with a Integer @Entity(name=customer) public Customer { ... @Column private
I've got the entity that contains @version field. Sometimes I need to update it
I've got an MVVM application that uses Entity Framework 4.1, WPF and C#. I
I've got a problem with the Entity Framework and the ForeignKeys. I've got a
I've got a problem at saving my entity. MApping: ?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping
Got classical Hibernate problem: Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: entry.Authority
I've got new project on the go and I'm looking at using the Entity
i've got following example xml: <entity id=1> <name>computer</name> <type>category</type> <entities> <entity id=2> <name>mac</name> <type>category</type>

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.