-->
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: Foreign Key Constraint Specification in Hibernate
PostPosted: Thu Apr 16, 2009 1:02 pm 
Newbie

Joined: Wed Nov 28, 2007 5:53 pm
Posts: 3
Hello Folks,

I am creating an application that uses hibernate for database design.

There are two tables:
DocumentType and DocBatch

The following are the hbm files for each

<hibernate-mapping package="com.mccamish.domain.mapping">
<class name="DocumentType" table="DOCUMENTTYPE">
<id name="id"
column="DOCTYPEID"
type="long"
unsaved-value="0">
<generator class="native"/>
</id>

<property name="carrier" unique="true"> <column name="CARRIER" sql-type="VARCHAR(50)"/> </property>
<property name="prodId" unique="true"> <column name="PRODID" sql-type="VARCHAR(50)"/> </property>
<property name="srcSysDocId" unique="true"> <column name="SRCSYSDOCID" sql-type="VARCHAR(50)"/> </property>
<property name="srcSystem" unique="true"> <column name="SRCSYSTEM" sql-type="VARCHAR(50)"/> </property>
<property name="docDescription"> <column name="DOCDESCRIPTION" sql-type="VARCHAR(150)"/> </property>
</class>
</hibernate-mapping>



<hibernate-mapping package="com.mccamish.domain.mapping">
<class name="DocBatch" table="DOCBATCH">
<id name="id"
column="DOCBATCHID"
type="long"
unsaved-value="0">
<generator class="native"/>
</id>


<property name="docTypeId"> <column name="DOCTYPEID" sql-type="BIGINT"/></property>
<property name="openInd"> <column name="OPENIND" /></property>
<property name="docBatchConsolidatedFileLoc"> <column name="DOCBATCHCONSOLIDATEDLFILELOC" sql-type="VARCHAR(150)"/></property>
<property name="environment"> <column name="ENVIRONMENT" sql-type="VARCHAR(50)"/></property>
<property name="batchOpen"> <column name="BATCHOPEN" sql-type="DATE"/></property>
<property name="batchClose"> <column name="BATCHCLOSE" sql-type="DATE"/></property>
</class>
</hibernate-mapping>



I would like to define DOCTYPEID in the DocBatch table as a foriegn key having a relationship with the DOCTYPEID column in the DocumentType table.

How can I specify this in the hibernate mapping file?

Can someone point me in the right direction?

Thanks,
Kunal



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

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:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

[code][/code]


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.