-->
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: complicated mapping problem
PostPosted: Thu Mar 02, 2006 8:45 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hibernate version: 3.1

I need to import data only and did not want to use a join to read the data.
The problem is I did not managed to figure out a working mapping for my problem. The tables are coming from oscommerce and are IMHO not properly designed.
an attribute can have options in multiple languages. So option has a composite-pk of products_options_id,language_id.

I cannot find a solution to define a relation between attribute and option because the column products_options_id of product_options does not point to the primary key of products_attributes but to another column. The expected behaviour of normal many to many mappings is that the foreign key does always point to the primary key of a table.
Does anybody have an idea?
Best Regards Sebastian

Code:
CREATE TABLE  `shop`.`products_attributes` (
  `products_attributes_id` int(11) NOT NULL auto_increment,
  `options_id` int(11) NOT NULL default '0',
  PRIMARY KEY  (`products_attributes_id`),
) ;
-- hint: options_id has a relation to products_options_id
CREATE TABLE  `shop`.`products_options` (
  `products_options_id` int(11) NOT NULL default '0',
  `language_id` int(11) NOT NULL default '1',
  `products_options_name` varchar(32) collate latin1_german1_ci NOT NULL default '',
  PRIMARY KEY  (`products_options_id`,`language_id`)
);
CREATE TABLE  `shop`.`languages` (
  `languages_id` int(11) NOT NULL auto_increment,
  `name` varchar(32) collate latin1_german1_ci NOT NULL default '',
  PRIMARY KEY  (`languages_id`)
);

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:47 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hier zwei mögliche Lösungen, die erste unter Verzicht von bestimmten Einträgen.
Code:
    <many-to-one name="options" unique="false" class="ProductsOptions">
      <column name="options_id"></column>
      <formula>1</formula>
    </many-to-one>


    <set name="optionValues">

      <key property-ref="optionsValuesId">
        <column name="products_options_values_id"></column>
      </key>
      <one-to-many class="ProductsOptionsValues" />
    </set>
   <property name="optionsValuesId" column="options_values_id"></property>

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.