-->
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: Extend entity with many-to-many relation
PostPosted: Tue May 12, 2015 2:39 pm 
Newbie

Joined: Tue May 12, 2015 1:02 pm
Posts: 1
Could you please help me with such case?

I have simple <Entity1>

@Entity
@Table(name="ENTITY1")
public class Entity1 {
@Id
@GeneratedValue
private Long id;

@Column(name="name")
private String name;
}

and I need without changing it (because <Entity1> is in another library) introduce many-to-many relation between the <Entity1> and <Item>.

Will it be enough just do like this:

@Entity
public class Entity2 extends Entity1 {

Set<Element> elements;

@ManyToMany(targetEntity = Element.class, fetch = FetchType.LAZY)
@JoinTable(
name = "entity1_element",
joinColumns = {@JoinColumn(name = "ent_id")},
inverseJoinColumns = {@JoinColumn(name = "elm_id")}
)
public Set<Element> getElement() {
return this.elements;
}
...

}

Or there is a better way to do it?

Thank you


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.