aspose file tools*
The moose likes Object Relational Mapping and the fly likes mapping One-to-many relationships using NetBeans and Not Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mapping One-to-many relationships using NetBeans and Not Hibernate" Watch "mapping One-to-many relationships using NetBeans and Not Hibernate" New topic
Author

mapping One-to-many relationships using NetBeans and Not Hibernate

Ylva Degerfeldt
Ranch Hand

Joined: Feb 12, 2008
Posts: 30
Hello,

I'm having problems with mapping the one-to-many relationships of my entities to my database.

Some software info:
I'm using MySQL Server 5.0, NetBeans 5.5.1 and Sun Java System Application Server 9.1. I'm using TopLink as persistence provider. (I Don't want to use Hibernate now because I'm doing a thesis on comparing using Hibernate to not using it, actually.)

I created my database (called "cv_database") from the MySQL command line client and then I generated entities from it using NetBeans. (That's the way I wanted to do it.) I've tested creating and saving some objects to the database but it doesn't work for my main table - CV - because it has three one-to-many relationships and those aren't correctly mapped..

I want the one-to-many relationships to be unidirectional and I read that in that case I need an extra "reference table" for each such relationship. So I created three such tables. Perhaps I should show you the Sql code for the significant tables:



One of the reference tables:



The other two reference tables have the same structure but connects the cv table to the tables Skillinstance and Workexperience.

It might also be important to show you the most important parts of the code for the Cv entity:


---

The real question is mostly about NetBeans (and I'm rather new to that): Is there a way to make NetBeans (5.5.1) automatically use my reference tables (or create new appropriate tables) just through the OneToMany annotation? I think there IS a way when you start with the entity code and generate a database from that. My problem is just that I wanted to try it the other way around and I'm not sure how to do it.

When I try to persist a Cv object I get an EJBException (without much explanation), which I consider a sign that the Cv table can't be matched with the Cv entity.

Is there some setting in NetBeans that I should use? (I've tried searching in the NetBeans help files but I didn't find anything that suited my problem.)
I shouldn't have to create entities for the reference tables and explicitly fill them with information, should I?

I also wonder if it's the entity code or the database schema that controls what actually happens, for instance, considering the GeneratedValue annotation. I added that myself but I'm not sure I really need it since the corresponding database field has "auto_increment" as part of its type.

Can somebody please shred some light on this whole thing? I would be very grateful.

Thanks

/Ylva
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mapping One-to-many relationships using NetBeans and Not Hibernate