File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA (TopLink) @ManyToMany generates strange tables

 
Morten Franorge
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm setting up a @ManyToMany relation in my object model, but I'm having strange results when Toplink generates the join table for me.






When using this mapping, TopLink Generates the following SQL:


The problem is the primary key. It uses employee_id as PK, however this contraint would restrict the object model. Only allowing the employee to have one project.

I've also tried to set a uniqueConstraint in the @JoinTable annotation, like this:

The result was the same SQL.

When I removed the @JoinTable annotation, the following SQL was created:

This is slightly better, but this allows multiple rows setting up the same project-employee relation.

In a production enviroment I would of course not use the table generation, however the way that Toplink generates the tables makes testing more time consuming.

Any one who knows what I'm doing wrong? Or is it TopLink's fault?
[ November 07, 2006: Message edited by: Morten Fra Norge ]
 
Mike Keith
author
Ranch Hand
Posts: 304
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Morten,

I tried doing what you did and the table got generated correctly with the compound PK containing both fields when I used the UniqueConstraint element. I might have a newer version of TopLink Essentials than you though since I just recently got a fresh version.

-Mike
 
Morten Franorge
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Keith:
Hi Morten,

I tried doing what you did and the table got generated correctly with the compound PK containing both fields when I used the UniqueConstraint element. I might have a newer version of TopLink Essentials than you though since I just recently got a fresh version.

-Mike


Which db did you use? I tried using HSQL. I finally got it working now though, not sure what changed the generated code. Might be a problem with my build tools...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic