Duniya,
I added a class Roles and compiled the sample code I posted. I put the class files in a JAR and uploaded at the tool I mentioned -
http://www.javatosql.com. Here are the results of the sql and some hibernate mappings so you can see how some of the relationships are mapped. If you want to see all the relationships, you can do the same thing as I described above.
SQL:
Code:
CREATE TABLE COMPANY
(
ID INTEGER NOT NULL AUTO_INCREMENT,
NAME VARCHAR(255) NOT NULL,
USER_ID_USER INTEGER NOT NULL,
PRIMARY KEY(ID)) engine=InnoDB;
CREATE TABLE JOB
(
ID INTEGER NOT NULL AUTO_INCREMENT,
DESCRIPTION VARCHAR(255) NOT NULL,
TITLE VARCHAR(255) NOT NULL,
COMPANY_ID INTEGER NOT NULL,
PRIMARY KEY(ID)) engine=InnoDB;
CREATE TABLE JOB_SEEKER
(
ID INTEGER NOT NULL AUTO_INCREMENT,
USER_ID_USER INTEGER NOT NULL,
PRIMARY KEY(ID)) engine=InnoDB;
CREATE TABLE ROLES
(
ID INTEGER NOT NULL AUTO_INCREMENT,
USER_ID INTEGER NOT NULL,
PRIMARY KEY(ID)) engine=InnoDB;
CREATE TABLE USER
(
ID INTEGER NOT NULL AUTO_INCREMENT,
EMAIL VARCHAR(255) NOT NULL,
LOGIN_ID VARCHAR(255) NOT NULL,
NAME VARCHAR(255) NOT NULL,
PASSWORD VARCHAR(255) NOT NULL,
PRIMARY KEY(ID)) engine=InnoDB;
ALTER TABLE COMPANY
ADD CONSTRAINT COMPANY_FK_USER_ID_USER
FOREIGN KEY (USER_ID_USER)
REFERENCES USER (ID)
ON DELETE CASCADE
;
ALTER TABLE JOB
ADD CONSTRAINT JOB_FK_COMPANY_ID
FOREIGN KEY (COMPANY_ID)
REFERENCES COMPANY (ID)
ON DELETE CASCADE
;
ALTER TABLE JOB_SEEKER
ADD CONSTRAINT JOB_SEEKER_FK_USER_ID_USER
FOREIGN KEY (USER_ID_USER)
REFERENCES USER (ID)
ON DELETE CASCADE
;
ALTER TABLE ROLES
ADD CONSTRAINT ROLES_FK_USER_ID
FOREIGN KEY (USER_ID)
REFERENCES USER (ID)
ON DELETE CASCADE
;
MAPPING FOR COMPANY:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Company" table="COMPANY">
<id column="ID" name="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property length="255" name="name" not-null="true" type="java.lang.String">
<column name="NAME" sql-type="VARCHAR"/>
</property>
<many-to-one class="User" name="user" not-null="true">
<column name="USER_ID_USER"/>
</many-to-one>
</class>
</hibernate-mapping>
MAPPING FOR USER:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="User" table="USER">
<id column="ID" name="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property length="255" name="email" not-null="true" type="java.lang.String">
<column name="EMAIL" sql-type="VARCHAR"/>
</property>
<property length="255" name="loginId" not-null="true" type="java.lang.String">
<column name="LOGIN_ID" sql-type="VARCHAR"/>
</property>
<property length="255" name="name" not-null="true" type="java.lang.String">
<column name="NAME" sql-type="VARCHAR"/>
</property>
<property length="255" name="password" not-null="true" type="java.lang.String">
<column name="PASSWORD" sql-type="VARCHAR"/>
</property>
<one-to-one class="Company" name="company"/>
<one-to-one class="JobSeeker" name="jobSeeker"/>
</class>
</hibernate-mapping>