How to do with hibernate Criteria to get the right result

General Tech Technology & Software 3 years ago

2.31K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 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!

0 views
0 shares

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.

Similar Forum