Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I am a Hibernate novice and was seeking help from anyone who could help me map the following db table creation sql to a hibernate mapping. I have alreading created the basic hibernate mapping defining the columns and primary. I need help with mapping the relationship (foreign keys) and the relationships between two tables. Listed below are the three tables and their hibernate mappings. Any help with modifying the mappings so that the accurately reflect the relationship between them will be very highly appreciated!
CREATE TABLE BUSINESS_ENTITY
(
BUSINESS_KEY VARCHAR(41) NOT NULL,
AUTHORIZED_NAME VARCHAR(255) NOT NULL,
PUBLISHER_ID VARCHAR(20) NULL,
OPERATOR VARCHAR(255) NOT NULL,
LAST_UPDATE TIMESTAMP NOT NULL,
PRIMARY KEY (BUSINESS_KEY)
);
CREATE TABLE CONTACT
(
BUSINESS_KEY VARCHAR(41) NOT NULL,
CONTACT_ID INT NOT NULL,
USE_TYPE VARCHAR(255) NULL,
PERSON_NAME VARCHAR(255) NOT NULL,
PRIMARY KEY (BUSINESS_KEY,CONTACT_ID),
FOREIGN KEY (BUSINESS_KEY)
REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);
CREATE TABLE CONTACT_DESCR
(
BUSINESS_KEY VARCHAR(41) NOT NULL,
CONTACT_ID INT NOT NULL,
CONTACT_DESCR_ID INT NOT NULL,
LANG_CODE VARCHAR(5) NULL,
DESCR VARCHAR(255) NOT NULL,
PRIMARY KEY (BUSINESS_KEY,CONTACT_ID,CONTACT_DESCR_ID),
FOREIGN KEY (BUSINESS_KEY,CONTACT_ID)
REFERENCES CONTACT (BUSINESS_KEY,CONTACT_ID)
);
<hibernate-mapping package="com.weblayers.common.bean.juddi">
<class name="BusinessEntity" table="BUSINESS_ENTITY">
<cache usage="read-write" region="com.weblayers.cache.BusinessEntityCache"/>
<id name="businessKey" column="BUSINESS_KEY" type="java.lang.String" length="41">
<generator class="assigned"/>
</id>
<!-- <version name="objectVersion" column="OBJECT_VERSION" type="java.lang.Integer"/> -->
<property name="authorizedName" column="AUTHORIZED_NAME" type="java.lang.String" length="255" not-null="true"/>
<property name="publisherId" column="PUBLISHER_ID" type="java.lang.String" length="20" />
<property name="operator" column="OPERATOR" type="java.lang.String" length="255" not-null="true"/>
<property name="lastUpdate" column="LAST_UPDATE" type="timestamp" not-null="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.weblayers.common.bean.juddi">
<class name="Contact" table="CONTACT">
<!-- <meta attribute="implements">com.weblayers.common.api.DataBean</meta> -->
<cache usage="read-write" region="com.weblayers.cache.ContactCache"/>
<composite-id name="contactKey" class="ContactKey">
<key-property name="businessKey" column="BUSINESS_KEY" type="java.lang.String" length="41" />
<key-property name="contactId" column="CONTACT_ID" type="integer"/>
</composite-id>
<property name="useType" column="USE_TYPE" type="java.lang.String" length="255"/>
<property name="personName" column="PERSON_NAME" type="java.lang.String" length="255" not-null="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.weblayers.common.bean.juddi">
<class name="ContactDescr" table="CONTACT_DESCR">
<cache usage="read-write" region="com.weblayers.cache.ContactDescrCache"/>
<composite-id name="contactDescrKey" class="ContactDescrKey">
<key-property name="businessKey" column="BUSINESS_KEY" type="java.lang.String" length="41" />
<key-property name="contactId" column="CONTACT_ID" type="integer" />
<key-property name="contactDescrId" column="CONTACT_DESCR_ID" type="integer" />
</composite-id>
<property name="langCode" column="LANG_CODE" type="java.lang.String" length="5"/>
<property name="descr" column="DESCR" type="java.lang.String" length="255" not-null="true"/>
</class>
</hibernate-mapping>