-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hbm2ddl problem with many-to-many entities relationship.
PostPosted: Mon May 18, 2009 10:32 pm 
Newbie

Joined: Thu Nov 06, 2008 4:38 am
Posts: 1
Location: vietnam
I have three entities: Category, Item and User.They have a ternary relationship with each others (this is an example in Java Persistence With Hibernate).
The mapping of Category entity:
Code:
@ManyToMany
    @MapKeyManyToMany(joinColumns = @JoinColumn(name = "ITEM_ID"))
    @JoinTable(name = "CATEGORY_ITEM",
    joinColumns = @JoinColumn(name = "FK_CATEGORY_ID"),
    inverseJoinColumns =
        @JoinColumn(name = "FK_USER_ID"))
    private Map<Item, User> items = new HashMap<Item, User>();

The mapping of Item:
Code:
    @ManyToMany(mappedBy = "items")
    public Set<Category> getCategories() {
        return categories;
    }

The schema which is generated by hbm2ddl is very strange, instead of generating a table with a composite key of foreign keys to CATEGORY, ITEM tables and a foreign key to USER table, it doesn't do so.
Here is the structure of generated table:
Image

Anyone can tell me this incorrect generated schema due to my incorrect mapping or a bug in hibernate. I have tried to test with hibernate 3.2.5 and 3.3.1.

Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.