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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:01:12+00:00 2026-06-10T06:01:12+00:00

@Entity public class doctor { @Id private int id; private String username; private String

  • 0
@Entity
public class doctor {
   @Id
   private int id;
   private String username;
   private String password;
   private String phone;
   private String email;

   @OneToMany(targetEntity = patient.class, cascade = CascadeType.ALL, mappedBy = "doctor")
   @Cascade(value = org.hibernate.annotations.CascadeType.ALL)
   private Collection<patient> patients = new ArrayList<patient>();
}

@Entity
public class patient {
   @Id
   private int id;
   private String name;
   private String surname;
   private String phone;
   private int systolic;
   private int diastolic;

   @ManyToOne
   private doctor doctor;
}

For now i can retreive only doctors information by this criteria:

Criteria query = session.createCriteria(doctor.class);
query.createCriteria("patients", "p");
query.add(Restrictions.eq("p.phone", phone));
List<doctor> doctorList = (ArrayList<doctor>) query.list();

How i can with hibernate criteria retreive by giving patient phone, his doctor information and some patients information?

Something like : phone=3423423424 , then answear is :

————-doctor’s info———————————-patientinfo(systolic,diastolic)———————–

  1 "Dr dre" sdfssd 243242 drdre@gmail.com  160 170

where 160 170 are the patient’s information

If not with criteria, with HQL?

  • 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-10T06:01:13+00:00Added an answer on June 10, 2026 at 6:01 am

    You have bidirectional mapping so from each doctor you can get his patients and from each patient you can get his doctor information. If you need a list with patients instead a list of doctors just create analogous Criteria for patients. session.createCriteria(patient.class), with needed restrictions. you don’t have to make it eager. In most cases we don’t need eager fetching. It is much better initialize (Hibernate.initialize) the collection or proxy if you would need the objects outside the hibernate session.

    btw use camel case when you name java classes. It’s widely used convention.

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

Sidebar

Related Questions

@Entity public class Parent { @Id @GeneratedValue(strategy=GenerationType.TABLE) int id; @OneToMany(cascade=CascadeType.REMOVE) List<Item> children = new
Let's say we have: @Entity public class Order { @Id private int id; @OneToMany(mappedBy=order)
@Entity public class TestClass implements Serializable{ private Integer id; private Set<String> mySet; @Id @GeneratedValue
@Entity public class Blobx { private String name; private BlobKey blobKey; @Id @GeneratedValue(strategy =
@Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version
I have two entities @Entity public class Tabulka{ @OneToMany(mappedBy = tabulka) private List<VysledkyHraca> vysledkyHraca;
@Entity public class Master implements Serializable{ private List slaves; @OneToMany(mappedBy = Master,fetch=FetchType.LAZY) public List
I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id;
When I run the following class: @Entity public class SurveyResponse { @Id private String
I have two JPA entities: @Entity public class TaskSchedule { ... private String name;

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.