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: