Hi all
I'm having a hard time getting the code generator to create POJOs for my <one-to-one> relationships
Whenever I include <one-to-one> in my mapping files I get the following exception
Code:
Error reading included file hbm/one-to-one.hbm.ftl
The problematic instruction:
----------
==> include "${c2h.getTag(property)}.hbm.ftl" [on line 73, column 1 in hbm/persistentclass.hbm.ftl]
in include "persistentclass.hbm.ftl" [on line 34, column 1 in hbm/hibernate-mapping.hbm.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateException: Error reading included file hbm/one-to-one.hbm.ftl
at freemarker.core.Include.accept(Include.java:153)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
...
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO
...
Caused by: java.io.FileNotFoundException: Template hbm/one-to-one.hbm.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:441)
The first thing that caused me a bit of concern is the reference to
hbm2x packages when all of my hbm.xml files are actually Hibernate 3.x files. Is this normal?
Basically what I want to do is to get a one to one relationship working between my Person class and my Player class. My MYSQL DDL is as follows
Code:
CREATE TABLE `person` (
`person_id` int(10) unsigned NOT NULL auto_increment,
`surname` varchar(45) NOT NULL default '',
`first_names` varchar(45) default NULL,
PRIMARY KEY (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `player` (
`person_id` int(10) unsigned NOT NULL default '0',
`endurance` decimal(6,2) NOT NULL default '0.00',
`form` decimal(6,2) NOT NULL default '0.00',
PRIMARY KEY (`person_id`),
CONSTRAINT `fk_player_person` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
So the person is the parent in the relationship. A player row cannot exist without an associated person row. A person can be no more than one player.
Below is my attempt at creating a one-to-one relationship
Code:
(person.hbm.xml excerpt)
...
<class name="com.mk.cricket.model.Person" table="person" catalog="cricket">
<comment></comment>
<id name="personId" type="int">
<column name="person_id" />
<generator class="identity" />
</id>
<one-to-one name="player"/>
...
(player.hbm.xml excerpt)
...
<class name="com.mk.cricket.model.Player" table="player" catalog="cricket">
<comment></comment>
<id name="personId" column="personId">
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<one-to-one name="person" constrained="true"/>
...
I guess there must be something fairly obvious I am doing wrong? Can someone give me a couple of pointers regarding how I should declare this relationship so the code generator works?
EDIT: I'm using Hibernate Tools 3.2.0.beta6a on Eclipse 3.2