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.  [ 2 posts ] 
Author Message
 Post subject: Mapping a db table with relationship to Hibernate mapping
PostPosted: Tue Jan 03, 2006 6:51 pm 
Newbie

Joined: Wed Jul 06, 2005 8:54 am
Posts: 2
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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 12:39 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
Why don;t you use hibernate tools to do the mapping for you? Hibernate tools comes in tool flavors Eclipse plugin and ant script. If you view the online doucmentation look at <one-to-many> and <many-to-one> examples this should help you.


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

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.