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.  [ 2 posts ] 
Author Message
 Post subject: Does the code generator work for one-to-one relationships?
PostPosted: Thu Aug 10, 2006 7:03 pm 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 5:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Create a JIRA entry for the one-2-one.

As far as hbm2x - the 2 in this context mean convert of if you like 'To' and has nothing to do with hibernates version.


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