aspose file tools*
The moose likes Object Relational Mapping and the fly likes [JPA - Hibernate] OneToMany without join table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[JPA - Hibernate] OneToMany without join table" Watch "[JPA - Hibernate] OneToMany without join table" New topic
Author

[JPA - Hibernate] OneToMany without join table

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I have 2 Objects for this question.

Color.java
--id
--name
--description

--@OneToMany
private List<ProductAttributes> attributes;

ProductAttributes.java
--id
--Color color

JPA is generating the Color and ProductAttributes tables but also it is creating a Color_ProductAttributes table. This table doesn't really need to be there, I don't think. So questions:

1. How to set up the annotations so that this table is not created
2. Will it perform better with/without the join table?


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Found my solution here.

Thanks.
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
What if you want to make it as unidirectional without a join table.

Thanks,
Rahul


Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Indeed, this is actually the default behavior for one to many associations, although it seems a bit weird when a simple foreign key would do.

I've got a simple "Team has many Players" mapping on my website that uses a database like this:




Mapping Many to One and One to Many Associations without a join table

The code is pretty straight forward:







Mapping Many to One and One to Many Associations without a join table

That Join Column annotation is really what does the trick.

-Cameron McKenzie
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Cameron,

If you had read the thread you would know that I already stated that I found the solution and linked to the very same page you are linking to.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [JPA - Hibernate] OneToMany without join table