-->
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: Mapping a unidirectional one-to-many relationship using bag
PostPosted: Tue Jun 17, 2008 12:58 pm 
Newbie

Joined: Fri Jun 13, 2008 4:52 pm
Posts: 9
Location: Västerås, Sweden
Hi all,

I'm new to Hibernate and am currently having problems with writing a correct Hibernate mapping file for a class.

The problem is that I have a unidirectional one-to-many relationship which is using a join table, in my class (called Cv). It has a java.util.list of Skillinstances (another of my classes). The join table I'm using is called cv_skillinstance.

I've tried to write a hbm(.xml) file for the class, according to a tutorial at:

http://www.hibernate.org

But I get a couple of errors when validating the hbm file.
This is the file so far:

Code:
<hibernate-mapping>
    <class name = "JavaBean_POJOS.Cv" table="cv">
        <id name = "cvId" column="cvId">
            <generator class = "native"/>
        </id>
        <one-to-one name = "person" foreign-key= "personId" class = "JavaBean_POJOS.Person" cascade = "merge" fetch = "join"/>
        <property name = "pathToCvFile"/>
        <bag name = "skills" table = "cv_skillinstance" cascade = "save-update|delete">
            <key column = "cvId" on-delete = "cascade" not-null = "true"/>
            <one-to-many column = "skillInstId" class="JavaBean_POJOS.Skillinstance"/>
        </bag>
    </class>
</hibernate-mapping>


It's the part under the "bag" element that I'm unsure of. I'm wondering two things:

1. How do I specify that my "skills" list should have cascade set to "create" And "remove" (using "Java talk")? Is it correct the way I've done it? (Can I remove the"on-delete = cascade"? I kept it just in case but I think it's a bit redundant.

2. The xml validator (of NetBeans 5.5.1) is complaining about the "column" attribute of the one-to-many element, but I think I have to write it somewhere since I'm using a join table. There's no other way of knowing what the foreign key of the join table is called (which is connected to the skillinstance table ). Should I write this somewhere else or what should I do?

I can add that I'm not changing the database (if someone would suggest that), because it's part of a bigger project and must remain the same.

I'd be very grateful for some help!
Thanks!

/Ylva


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.