java - inner join between two tables Hibernate -


i need inner join between 2 tables, without success, have find patients related particular user,i tried query without success. using mysql , hibernate 3.6.4. code

patient.java

@entity public class patient {      @id     private int id;     private string paitentfirstname;     private string paitentlastname;     private date dateofbirth;     private string sex;       @manytomany(cascade = {cascadetype.all})         @jointable(name="user_patient",                      joincolumns={@joincolumn(name="id")},                      inversejoincolumns={@joincolumn(name="username")})         private set<user> users = new hashset<user>();       public set<user> getusers() {         return users;     }     public void setmeetings(set<user> users) {         this.users = users;     }     public int getid() {         return id;     }     public void setid(int id) {         this.id = id;     }     public string getpaitentfirstname() {         return paitentfirstname;     }     public void setpaitentfirstname(string paitentfirstname) {         this.paitentfirstname = paitentfirstname;     }     public string getpaitentlastname() {         return paitentlastname;     }     public void setpaitentlastname(string paitentlastname) {         this.paitentlastname = paitentlastname;     }     public date getdateofbirth() {         return dateofbirth;     }     public void setdateofbirth(date dateofbirth) {         this.dateofbirth = dateofbirth;     }     public string getsex() {         return sex;     }     public void setsex(string sex) {         this.sex = sex;     }     @override     public string tostring() {         return "patient [id=" + id + ", paitentfirstname=" + paitentfirstname                 + ", paitentlastname=" + paitentlastname + ", dateofbirth="                 + dateofbirth + ", sex=" + sex + "]";     }  } 

user.java

@entity public class user {        @id     private string username;       @manytomany(mappedby="users")         private set<patient> patients = new hashset<patient>();      public string getusername() {         return username;     }     public void setusername(string username) {         username = username;     }     public set<patient> getemployees() {         return patients;     }     public void setemployees(set<patient> patients) {         this.patients = patients;     }     public string getpassword() {         return password;     }     public void setpassword(string password) {         this.password = password;     }     private string password; } 

hibernate configuration file

   <?xml version='1.0' encoding='utf-8'?>  <!doctype hibernate-configuration public         "-//hibernate/hibernate configuration dtd 3.0//en"         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">  <hibernate-configuration>      <session-factory>          <!-- database connection settings -->     <property name="connection.driver_class">com.mysql.jdbc.driver</property>         <property name="connection.url">jdbc:mysql://localhost:3306/test2</property>         <property name="connection.username">root</property>         <property name="connection.password">1234</property>          <!-- jdbc connection pool (use built-in) -->         <property name="connection.pool_size">1</property>          <!-- sql dialect -->         <property name="dialect">org.hibernate.dialect.mysqldialect</property>          <!-- disable second-level cache  -->         <property name="cache.provider_class">org.hibernate.cache.nocacheprovider</property>          <!-- echo executed sql stdout -->         <property name="show_sql">true</property>          <!-- drop , re-create database schema on startup -->         <property name="hbm2ddl.auto">update</property>          <!-- names annotated entity class -->         <mapping class="com.objects.patient"/>         <mapping class="com.objects.user"/>      </session-factory>  </hibernate-configuration> 

there no need explicit join. hibernate version have hhh-5209 fixed, query can written follows:

select p patient p :particularuser member of p.users 

with older versions in elements can used instead:

select p patient p :particularuser in elements (p.users) 

Comments