-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to describe this scheme
PostPosted: Mon Dec 31, 2007 11:20 pm 
Newbie

Joined: Mon Dec 31, 2007 11:07 pm
Posts: 2
hi,

I am new to hibernate. After some reading and practise, I have got a basice understanding of hibernate and currently develeping a little application use it. However, I encounter a problem and don't know how to deal with it.

In my application, there is a table A(id,...) and B(id,...),and a many to many jointable C(a_id,b_id). This is quite simple, and the code fragment is something as following:

@Entity
@Table(name = "A")
public class Item extends BaseObject {
private Long id;

private Set<B> bs = new HashSet<B>();

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}

...

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "C", joinColumns = { @JoinColumn(name = "A_id") }, inverseJoinColumns = @JoinColumn(name = "B_id"))
public Set<B> getBs() {
return bs;
}

...
}

Now, I need to add a new column to table C, which produce C(a_id,b_id,Commments).

Since C is a join table, there are no class definiton for it in my application, what should I do?

I think this is a common scene in many applicaton, so there must be some ways to achieve this in hibernate.

Any suggestion is appreciated and thanks in advance.


Top
 Profile  
 
 Post subject: Re: How to describe this scheme
PostPosted: Tue Jan 01, 2008 6:51 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You will need to define the relation as an entity itself. After that you can assign fields to the association. Take a look at this post http://forum.hibernate.org/viewtopic.php?t=981882&highlight=


Somewhere in the middle I did a little test that does something similar to this. That should answer your question.


Farzad-[/url]


Top
 Profile  
 
 Post subject: Thank you!
PostPosted: Tue Jan 01, 2008 9:07 pm 
Newbie

Joined: Mon Dec 31, 2007 11:07 pm
Posts: 2
Yes, I'm trying a new plan, use 2 1tomany associatians: A->C, B->C. That seems fit into my need, and I can have a POJO mapped to C now.

:-)


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

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.