-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Unable to generate tables using hibernate
PostPosted: Tue Nov 01, 2011 6:07 am 
Newbie

Joined: Tue Nov 01, 2011 5:55 am
Posts: 1
I am trying to generate some tables using hibernate. I have following classes :

Code:
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 :
Code:

+------------------------------+
      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 :

Code:
<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 :
Code:

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 generating tables properly? Or is there any way to generate tables manually and then just map those table with classes?

_________________
Thanks and Regards,
Chandrash3khar Kotekar


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.