-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bidirectional OneToOne
PostPosted: Mon Apr 16, 2007 3:57 pm 
Newbie

Joined: Wed Mar 28, 2007 4:00 pm
Posts: 7
I have followed the examples, but have never been able to get a Bidirectional OneToOne association to work.

Code:
@Entity
public class Server implements Serializable {
   
    private int serverId;
    private Task task;
   
    @Id
    @Column(name="server_id")
    public int getServerId() {
        return serverId;
    }

    @OneToOne
    @PrimaryKeyJoinColumn
//    @JoinColumn(name="task_id")
    public Task getTask() {
        return task;
    }
}

@Entity
public class Task implements Serializable {
    private int taskId;
    private Server server;

    @Id
    @Column(name="task_id")
    public int getTaskId() {
        return taskId;
    }

    @OneToOne(mappedBy = "server_id")
    public Server getServer() {
        return server;
    }
}


hibernatetool always gets a NullPointerException with the above code. If I comment out the getServer method and annotation, then I have a unidirectional association, but I still get the following error from hibernate tool:

hibernatetool org.hibernate.tool.hbm2x.ExporterException: Error while processing template hbm/hibernate-mapping.hbm.ftl
hibernatetool freemarker.template.TemplateException: Error reading included file hbm/one-to-one.hbm.ftl
hibernatetool java.io.FileNotFoundException: Template hbm/one-to-one.hbm.ftl not found.

Furthermore, if I change PrimaryKeyJoinColumn to JoinColumn, then the unidirectional association finally works.

I'm using
Hibernate 3.2.2.ga
HibernateAnnotations 3.3.0.GA
HibernateTools 3.2.0.beta8
Freemarker 2.3.4

How do I get the bidirectional association to work correctly? What is the deal with the *.hbm.ftl files?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it should be

@OneToOne(mappedBy = "task")

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 3:29 pm 
Newbie

Joined: Wed Mar 28, 2007 4:00 pm
Posts: 7
This helps me understand that it is a logical mapping and not a physical mapping that I need.

However, I still get the errors
- org.hibernate.tool.hbm2x.ExporterException: Error while processing template hbm/hibernate-mapping.hbm.ftl
- freemarker.template.TemplateException: Error reading included file hbm/one-to-one.hbm.ftl

What am I missing? Where do these files reside?


Top
 Profile  
 
 Post subject: hbm/one-to-one.hbm.ftl
PostPosted: Sat Apr 05, 2008 7:25 pm 
Newbie

Joined: Mon Mar 17, 2008 3:07 pm
Posts: 8
The following error message happens to me also whenever I try import hbm files that use one-to-one relationship:

freemarker.template.TemplateException: Error reading included file hbm/one-to-one.hbm.ftl

Actually, this message might be wrong once that template (ftl) is not in the standard hibernate tools package:

http://anonhibernate.labs.jboss.com/bra ... lates/hbm/

Please, someone explain that to us!


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