-->
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: String[] collection mapping hfor PARENT-CHILD relationship !
PostPosted: Tue Feb 21, 2006 5:45 am 
Newbie

Joined: Tue Feb 21, 2006 5:13 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1

Mapping documents:

Employee
|
/ \
/ \
Worker Head

table :
Employee:NAME (PK)
Employee:EMAIL
Employee:JOINDATE
Employee:TEAMHEADNAME

Worker:NAME
Worker:JOB
Worker:DEADLINE

Head:NAME
Head:BRANCH
etc..

Object:

Employee
get/setName (NAME)
get/setEmail
get/setJoinDate
get/setTeamHeadName (NAME of the head, an Employee)
get/setWorkersForHead (string[] of NAMES of Workers, where TEAMHEADNAME=NAME)

Similarly for Worker and Head.

In my application,

>> Base Object is 'Employee'

>> I can create Worker or Head Objects.

>> NAME is PK Column and TEAMHEADNAME can be a NOT-NULL Column, but not a PK/FK.

>> While retrieving a 'Head' Objects, I need to fill 'WrorkersForHead' names String[]. (say output of select NAME from Emploee where TEAMHEADNAME=NAME; here NAME is (Head.NAME)).

How should I capture this in 'Employee' mapping ?

My mapping ..

<array name="teamHeadName" table="Employee">
<key column="TEAMHEADNAME" not-null="true" unique="false"/>
<list-index column="NAME"/>
<element column="NAME" type="string"/>
</array>

What should I do, to map 'TEAMHEADNAME' for where criteria ?

Exception trace :
[java] Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (FKB8
55B9E7719968D:Employee [TEAMHEADNAME])) must have same number of columns as the referenced primary
key (Employee [TEAMHEADNAME,NAME])
[java] java.lang.ExceptionInInitializerError
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at samples.ORManager.getMO(Unknown Source)
[java] at samples.ORManager.main(Unknown Source)
[java] Caused by: org.hibernate.MappingException: Foreign key (FKB855B9E7719968D:Employee
[TEAMHEADNAME])) must have same number of columns as the referenced primary key (Employee [TEAMHEADNAME,NAME])
[java] at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
[java] 15:11:27,766 INFO Configuration:1035 - processing association property references
[java] 15:11:27,766 INFO Configuration:1057 - processing foreign key constraints
[java] at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
[java] at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1
123)
[java] at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1
120)
[java] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1062)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1146)
[java] ... 3 more
[java] Exception in thread "main"
[java] Java Result: 1

:smiledreamz:


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.