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