How to do with hibernate Criteria to get the right result

General Tech Technology & Software 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have two classes named Expert and Technology, an expert can maitrise several technologies, a technology is matrised by several experts. Adding, updating a technology is independent from class Expert. Remove a maitrised technology from the experts remove only the associated relation.

Class Expert{
     Long id; // getter and setter
     String name; // getter and setter;
     Set<Technology> technos; // getter and setter
} 

Technology{
     Long id; // gettter and setter
     String name; //getter and setter
}

The relation between the two classes reflected in the hibernate mapping is

 name="Expert">
     

    <set name="technos" table="EXPERT_TECHNO" cascade="delete-orphan">
            <key column="id_expert"/>
             column="id_techno" class = "Technology"/>
    set>


 name="Technology">
 

Now I have a instance of Technology, I want to find all experts who maitrise the technology, so how to use hibernate critera to get the result set? Or the simplest way to get the result set using createQuery.

I am not famillar to hibernate critera method, so i call for your helps!

Further question:

when I want a remove a technology from expert, what I want is simply remove a line in the table "EXPET_TECHNO", howevery, what I had is that expert.getTechnos.remove(techno),will remove the technology from the table which is what I don't want to have!

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.