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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:56:52+00:00 2026-05-27T01:56:52+00:00

i have one problem in one-to-many mapping using hibernate. i have 2 classes, Person

  • 0

i have one problem in one-to-many mapping using hibernate.

i have 2 classes, Person and Address. Person is mapped by Address ( one-to-many)
i want get all Person where Address = “xxxx”;. how to prepare this query using DetachedCriteria . below i have added a piece of code from my dao class. please help me to complete it.

Person.java

@Entity
@Table(name="PERSON")
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="personId")
     private int id;
    @Column(name="personName")
    private String name;
    @OneToMany(cascade =CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name="personId") 
    private Set <Address> addresses;
}

Address.java

@Entity
@Table(name = "ADDRESS")
public class Address {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "addressId")
    private int id;
    @Column(name = "address",nullable=false)
    private String address;
    @ManyToOne(cascade =CascadeType.ALL)
    @JoinColumn(name="personId",nullable=false)
    private Person person;
}

My DAO

DetachedCriteria c = DetachedCriteria.forClass(Person.class);
        List<Person> persnList =null;
        /*here i want add some restriction for
           fetch all person whose address = "abcd"
           here address is collection. how to set restriction in it ?.

           */
        persnList = getHibernateTemplate().findByCriteria(c);
        System.out.println(persnList.size());

select * from person where Address.address = “xxxx”; how to implement this using DetachedCriteria ?

  • 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-27T01:56:53+00:00Added an answer on May 27, 2026 at 1:56 am
    DetachedCriteria c = DetachedCriteria.forClass(Person.class);
        List<Person> persnList =null;
    
    DetachedCriteria addrCrit = c.createCriteria("addresses").addRestriction(Restrictions.eq("address","abcd"));
    addrCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    
        persnList = getHibernateTemplate().findByCriteria(c);
        System.out.println(persnList.size());
    

    Creating inner criteria on main criteria which will do an equivalent inner join.

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

Sidebar

Related Questions

I am having problem with my Hibernate Mapping. I have a many to one
I have one problem , I want to get some data from XML file
I have problem with one-to-many mapping. Two tables questions(PK(id), text) and answers(PK(id, questionId), text)
i have one problem when i sort the NSMutablearray using date and time wise.
I have one interesting problem. I must parse mail body (regular expression), get some
I have two entities, Job and Language , in a many-to-one relationship. The mapping
I have come across a weird problem concerning composite keys and one-to-many relationship. I
Entity Photos belongs to Property entity and one property can have many photos. Mapping
I am having problem with updating data to database. I have a simple many-to-one
I'm running into a performance problem in my SQL using Hibernate's DetachedCriteria. 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.