-->
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: Questions on one-to-many on varchar
PostPosted: Sun May 08, 2005 4:34 am 
Newbie

Joined: Sun May 08, 2005 4:17 am
Posts: 3
Hi,

I have created a Parent - Child table on mysql.
However, I did not use the primary key of the parent as a reference column on the child foreign key.
What I define is a varchar column ref varchar(8) on the parent and parent_ref on the child also a varchar(8)

When I create the mapping xml through JBoss-IDE Hibernate Eclipse plug in, everything looks find.

Thus, I tried to access the data from the parent table and it is successful.
However, if I define the parent ref column as alphabetic data, the retrieval of the child set is 0. But when i define the parent ref column with number data, I can retrieve the child set successful.

e.g.
Parent Id - 1, Parent ref - abc
Child Parent_id - abc
parent.getSetOfChild().size() // result is 0

Parent Id - 1, Parent ref - 1
Child Parent_id - 1
parent.getSetOfChild().size() // result is 1

Can anyone advice on what do I miss out?

Thanks in advance.



Han Ming

###############################
Code:
 
DROP TABLE IF EXISTS `test`.`parent`;
CREATE TABLE `parent` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `value` varchar(45) NOT NULL default '',
  `ref` varchar(8) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `Index_2` (`ref`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `test`.`child`;
CREATE TABLE `child` (
  `parent_id` varchar(8) NOT NULL default '0',
  `value` varchar(45) NOT NULL default '',
  KEY `FK_child_1` (`parent_id`),
  CONSTRAINT `FK_child_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`ref`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDB free: 4096 kB; (`parent_id`) REFER `test/parent`(`id`';


  <class name="com.db.test.Parent" table="parent" >
    <id name="Id" type="java.lang.Integer">
      <column name="id" scale="10" precision="0" not-null="true" sql-type="int unsigned" />
      <generator class="assigned" />
    </id>
    <property name="Value" type="java.lang.String">
      <column name="value" scale="45" precision="0" not-null="true" sql-type="varchar" />
    </property>
    <property name="Ref" type="java.lang.String">
      <column name="ref" scale="8" precision="0" not-null="true" unique="true" sql-type="varchar" />
    </property>
    <set name="SetOfChild">
      <key>
        <column name="parent_id" scale="10" precision="0" not-null="false" unique="true" />
      </key>
      <one-to-many class="com.db.test.Child" />
    </set>
  </class>

  <class name="com.db.test.Child" table="child" >
    <composite-id name="id" class="com.db.test.ChildId">
      <key-many-to-one name="Parent" class="com.db.test.Parent">
        <column name="parent_id" scale="10" precision="0" not-null="false" unique="true" />
      </key-many-to-one>
      <key-property name="Value" type="java.lang.String">
        <column name="value" scale="45" precision="0" not-null="true" sql-type="varchar" />
      </key-property>
    </composite-id>
  </class>


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.