I am trying to generate some tables using hibernate. I have following classes :
class Candidate {
long candidateID;
String candidate_name;
List<Project> projects;
}
class Project {
long projectID;
Set<String> technologies;
}
and I want to generate tables like below :
+------------------------------+
candidates
------------------------------|
candidate_id | candidate_name
+------------------------------+
+------------------------------+
projects
------------------------------|
candidate_id | project_id
+------------------------------+
+----------------------------------------+
project_technologies
-----------------------------------------|
candidate_id | project_id | technology_id
+----------------------------------------+
+------------------------------+
technologies
-------------------------------|
technology_id | technology_name
+------------------------------+
and currently mapping file for Project class is as follows :
<hibernate-mapping package="com.shekhar.tmpProject.model">
<class name="Project" table="PROJECTS">
<id name="projectID" column="PROJECT_ID" type="integer"
unsaved-value="0">
<generator class="native" />
</id>
<set name="technologies" table="PROJECT_TECHNOLOGIES">
<key column="PROJECT_ID" />
<element column="TECHNOLOGY_NAME" type="string" />
</set>
</class>
</hibernate_mapping>
but currently hibernate is not generating the tables the way I want. What I am getting now is something like as follows :
mysql> desc project_technologies;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| PROJECT_ID | int(11) | NO | PRI | NULL | |
| TECHNOLOGY | varchar(255) | NO | PRI | NULL | |
+------------+--------------+------+-----+---------+-------+
2 rows in set (0.03 sec)
mysql> desc projects;
+--------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------+------+-----+---------+----------------+
| PROJECT_ID | int(11) | NO | PRI | NULL | auto_increment |
| CANDIDATE_ID | bigint(20) | YES | MUL | NULL | |
+--------------+------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
mysql> desc candidates;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| CANDIDATE_ID | bigint(20) | NO | PRI | NULL | auto_increment |
| CANDIDATE_NAME | varchar(255) | NO | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
Can anyone please help me in this?
candidate_idin project_technologies? I think theproject_idwould be enouth