-->
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.  [ 4 posts ] 
Author Message
 Post subject: Saving one property to multiple tables
PostPosted: Thu Feb 08, 2007 7:31 pm 
Newbie

Joined: Thu Feb 08, 2007 4:43 pm
Posts: 7
Hibernate version: 2.1.7

Name and version of the database you are using: MySQL Server 5.0

Scenario:
    One Java class <ClassA> has a specific property <propertyA>.
    This Java class contains collections of other objects (ClassB, ClassC).
    ClassB and ClassC do not have propertyA defined in their Java class.
    The database tables mapped to these other classes (ClassB and ClassC) require propertyA of the container class (ClassA).


Question: How do I map these so that the property in ClassA is copied to the other tables when that property is not defined in the Java classes related to those tables? Is this even possible?

I'm very new to Hibernate and have checked the reference docs, tutorials, postings, etc., but could not find anything similar. Your help will be appreciated.


Top
 Profile  
 
 Post subject: mapping of property from another class
PostPosted: Fri Feb 09, 2007 3:44 am 
Beginner
Beginner

Joined: Wed Nov 15, 2006 4:25 am
Posts: 21
Hi

Can you send the database table design for your question ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 11:05 am 
Newbie

Joined: Thu Feb 08, 2007 4:43 pm
Posts: 7
Thank you, but someone has suggested I try using a composite-element in the container class. I'll try this and post the solution if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 11:11 am 
Newbie

Joined: Thu Feb 08, 2007 4:43 pm
Posts: 7
I was unable to get the composite key suggestion to work. Below is the MySql script for creating the table for the problem example:

Code:
`test`.CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */;

CREATE TABLE  `test`.`table_a` (
  `TableA_Id` decimal(10,0) NOT NULL,
  `PropertyA` varchar(3) NOT NULL,
  `AnotherProperty` varchar(45) NOT NULL,
  PRIMARY KEY  USING BTREE (`TableA_Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE  `test`.`table_b` (
  `PropertyA` varchar(3) NOT NULL,
  `TableA_Id` decimal(10,0) NOT NULL,
  `TableB_Id` decimal(10,0) NOT NULL,
  `someString` varchar(45) NOT NULL,
  PRIMARY KEY  (`TableA_Id`,`TableB_Id`),
  CONSTRAINT `FK_TableB_1` FOREIGN KEY (`TableA_Id`) REFERENCES `table_a` (`TableA_Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE  `test`.`table_c` (
  `PropertyA` varchar(3) NOT NULL,
  `TableA_Id` decimal(10,0) NOT NULL,
  `TableC_Id` decimal(10,0) NOT NULL,
  `someNumber` decimal(5,0) NOT NULL,
  PRIMARY KEY  (`TableA_Id`,`TableC_Id`),
  CONSTRAINT `FK_TableC_1` FOREIGN KEY (`TableA_Id`) REFERENCES `table_a` (`TableA_Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


This is a scaled down version of my actual database to demonstrate the problem of mapping a value from one table to many tables. Any help with the mapping would be greatly appreciated.
Code:
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.