Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

(yet another) Hibernate mapping question, using xdoclet

 
L Duperval
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following table definitions:

create table vehicle (
id char(10) primary key,
licenseplate char(10)
);

create table parts (
id char(10) primary key,
serialnum char(10),
);

create table vehicle_parts (
vehicle_id char(10),
parts_id char(10),
primary key (vehicle_id, parts_id);
)

How do I create a mapping that
- Allows a vehicle to have multiple parts
- Allows a part to be in only one vehicle
- Allows me to find the vehicle a part belongs to
- Allows me to find all the parts in the vehicle

If possible, I'd like it all to be done with xdoclet tags. I looked at the Hibernate documentation but I can't see the forest from the trees.

Thanks,

L
[ September 29, 2004: Message edited by: Laurent Duperval ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Laurent Duperval:
- Allows a vehicle to have multiple parts
- Allows a part to be in only one vehicle

This describes a one-to-many relationship, yet you have modeled a many-to-many. It will work, but it may be more complicated than it needs to be.

If you don't get an answer, I would highly recommend you post your question on the XDoclet user mailing list. One of the main developers (and several other frequent posters) use XDoclet with Hibernate. I'm starting next week, so I can't help with it yet.
 
L Duperval
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know, after posting my message, I realized that the vehicle_parts table was propably overkill. Let me try to remove it to see what happens.

Thanks,

L
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i wrote a tutorial on how to create hibernate mappings with xdoclet. you can find it here:
tutorial

if you use the hibernate/xdoclet combo, then you do not need to write the DDL statements (create tables). an ant task will take care of that (if you want to).

perhaps this helps.
pascal
[ October 06, 2004: Message edited by: pascal betz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic