-->
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: many to many, with join table and a composite key issue.
PostPosted: Fri Feb 10, 2012 9:26 am 
Newbie

Joined: Fri Feb 10, 2012 9:10 am
Posts: 1
Hi all, I have an issue with my current mappings and would to know if it's possible to create entities that will model my required relationship so that Hibernate will create my schema when I fire up my application.

The relationship I want looks like this:

Image

The thing is that the Join table can actually contain rows that don't link to any Elements. The structure represents categorising of elements based on the "type" and "value" pair and are entered in to the system outside of this particular application.

I know that this isn't great in terms of database design, but the problem i have is that I can't make any changes to the existing tables. I'm adding in ElementCategory and the join but can't do anything that will alter the layout in Element.

What I would like to be able to do is set my Element Hibernate Entity to contain a list of Categories, via a mapping, so that I can actually see what Categories my element belongs to AND so that hibernate creates the table for me.

Here's what I've got so far:
Code:

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "ELEMENT_ELEMENTCATOGORY", joinColumns = {
              @JoinColumn(name = "type", referencedColumnName = "type"),
         @JoinColumn(name = "value", referencedColumnName = "value") }, inverseJoinColumns = {
         @JoinColumn(name = "id", referencedColumnName = "id") }
   )
@Column(name = "category")
public List<ElementCategory> getCategories() {
    return categories;
}


This does most of what I want, it creates my tables as above, exactly how I want them bar one thing, there's a Unique Constraint added in to the Element Table on the (type,value) pair. I don't want this because multiple elements can have the same type and value pair, I need to be able to stop the Unique Constraint from begin created, but can't figure out how with the current mapping, can I do this? Am I missing the point of a Many to Many relationship?


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.