• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
  • Piet Souris

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

Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


    Bookmark Topic Watch Topic
  • New Topic