-->
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: Don't know how to map a table.
PostPosted: Fri Aug 17, 2007 12:39 pm 
Newbie

Joined: Sat Jul 22, 2006 3:08 pm
Posts: 6
Hibernate version: 3
Databese MySql


I'm having trouble creating mapping file for one of the tables.
Relation is one-to-many but the key is multicolumn:

The tables are as following:

CREATE TABLE item
(model_id INTEGER,
item_id INTEGER NOT NULL AUTO_INCREMENT,
type_id INTEGER NOT NULL,
item_name VARCHAR(100),
item_pic VARCHAR(60),
size_type VARCHAR(5),
item_desc TEXT,
PRIMARY KEY (item_id),
KEY (type_id),
KEY (model_id)) ;
ALTER TABLE item ADD CONSTRAINT FK_item_item_type
FOREIGN KEY (type_id) REFERENCES item_type (type_id);
ALTER TABLE item ADD CONSTRAINT FK_item_model
FOREIGN KEY (model_id) REFERENCES model (model_id);

CREATE TABLE item_sc
( item_id INTEGER,
color_id INTEGER,
num_size INTEGER,
char_size VARCHAR(4),
curr_stock INTEGER,
KEY (color_id),
KEY (item_id)) ;

ALTER TABLE item_sc ADD CONSTRAINT FK_item_sc_color_dict
FOREIGN KEY (color_id) REFERENCES color_dict (color_id);
ALTER TABLE item_sc ADD CONSTRAINT FK_item_sc_item
FOREIGN KEY (item_id) REFERENCES item (item_id);

CREATE TABLE color_dict
( color_id INTEGER NOT NULL AUTO_INCREMENT,
color_name VARCHAR(60) NOT NULL,
color_pic VARCHAR(60),
PRIMARY KEY (color_id)) ;

Mapping that I already have is for item and color tables (there are other tables referenced in it of course)

<hibernate-mapping>
<class name="axmar.dao.Item" table="item">
<id name="itemId" column="item_id">
<generator class="native"/>
</id>
<property name="modelId" column="model_id" insert="false" update="false"/>
<property name="itemName" column="item_name"/>
<property name="itemPic" column="item_pic"/>
<property name="sizeType" column="size_type"/>
<property name="itemDesc" column="item_desc"/>
<many-to-one name="type" class="axmar.dao.ItemType" column="type_id" lazy="false"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="axmar.dao.Color" table="color_dict">
<id name="colorId" column="color_id">
<generator class="native"/>
</id>
<property name="colorName" column="color_name"/>
<property name="colorPic" column="color_pic"/>

</class>
</hibernate-mapping>


How do I map item_sc table where
primary key is item_id+color_id?

What would be the class to map item_sc table?
Like this below ?

public class ItemSc {
private int itemId;
private int colorId;
private int numSize;
private String charSize;
private int currStock;}


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.