-->
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.  [ 7 posts ] 
Author Message
 Post subject: OneToMany to List<Integer> not List<ClassMappedInTa
PostPosted: Fri Mar 06, 2009 1:10 pm 
Newbie

Joined: Tue Apr 22, 2008 12:48 am
Posts: 9
Dear all,
I have in table, let's call it table A that is mapped into a class A. Then i have a table B that just contains 3 columns a_id, a reference to a value in the table A, position, and int_value.

I need to get in the class A a List<Integer> with the values from the table B ordered by the column 'position'. It looks very simple... and maybe it is, but all the examples i found map always first the table B to a class B and so they have something like:
@OneToMany(targetEntity = ClassB.class, cascade = CascadeType.ALL, mappedBy = "group", fetch = FetchType.LAZY)

But in this case there's no classB it is just an integer value. I can't see the way to tell hibernate to get the values from table B to create a list of integers in table a without making a silly class B extending Integer which i feel is very goofy.

Well... it looks as i said simple and i am sure there must be a way to solve it. I think it is a common thing so there must be a solution. Googeling didn't gelp much... i hope one of you guys know it.

Thanks in advance,
Dani.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 2:18 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
A List or a Bag might work in this case (without creating ClassB).
http://www.hibernate.org/hib_docs/annot ... ml_single/

LinHib.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 6:34 pm 
Newbie

Joined: Tue Apr 22, 2008 12:48 am
Posts: 9
Hi Lin,
thanks for your reply.
Yes, I need a List. It is a list of integers what i need to create from the table B, but i can't see the way even reding again about lists and bags to specify it to the hibernate without saying that it is a list of objects B where the class B has an annotation saying class B is mapped from table B. I just see, as I said, examples where thez use 'mappedBy' and specify another class. I don't see how to say, mappedBy(column X) and table B.
Dani.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 7:03 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
How about something like this:

@org.hibernate.annotations.CollectionOfElements(
targetElement = java.lang.Integer.class
)
@JoinTable(
name = "TableB",
joinColumns = @JoinColumn(name = "a_id?")
)
@Column(name = "POSITION")
private List<Integer> positions = new ArrayList<Integer>();


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 07, 2009 2:45 am 
Newbie

Joined: Tue Apr 22, 2008 12:48 am
Posts: 9
Hi Lin,
I can't wait till next Monday morning to try it!
I will tell you the result.
Thanks very much and have a nice weekend.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 7:07 am 
Newbie

Joined: Tue Apr 22, 2008 12:48 am
Posts: 9
Hi Lin,

thank you very much for your help. Your mesasge set me in the right direction.
The final version making it work is:

@org.hibernate.annotations.CollectionOfElements(
targetElement = java.lang.Integer.class
)
@JoinTable(
name = "tableB",
joinColumns = @JoinColumn(name = "Aid_in_B")
)
@IndexColumn(name="order_of_value_in_B", base = 1)
@Column(name = "value_in_B")

Thanks,
Dani.


Top
 Profile  
 
 Post subject: Re: OneToMany to List<Integer> not List<ClassMappedInTa
PostPosted: Thu Sep 24, 2009 8:10 am 
Newbie

Joined: Tue Jul 21, 2009 1:46 am
Posts: 5
Can any help me with this? It's similar but I need to do it without annotations and using the mapping xml instead:

I have a Center and Examinee as beans and a mapping table with id,examinee_id,center_id

I want to retrieve a list of center_id as a list in each Examinee bean. I origianlly had:

Code:
<set name="centers" lazy="false" order-by="center_id" inverse="true" cascade="all-delete-orphan" table="ot_examinee_center_map">
            <key column="examinee_id" />
            <many-to-many column="center_id" class="com.webaccess.onlinetest.model.beans.Center" />
</set>


but this gives a set with Center beans. I need to instead retrieve a List of center_id for each Examinee.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.