-->
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: Persisting a @CollectionOfElements (List<Integer>)
PostPosted: Fri Jul 31, 2009 12:17 pm 
Newbie

Joined: Fri Jul 31, 2009 12:09 pm
Posts: 2
Hello,

I'm trying to map a class which has a List<Integer> property. This list is persisted in a database table, which only has two columns, the foreign key to the mapped class, and the integer value.

My code is this:

@CollectionOfElements
@JoinTable(
name="resourceGroupHasResources",
joinColumns = { @JoinColumn(name="idResourceGroup") }
)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@Column(name="idResource")
public List<Integer> getResources(){...}

It works fine, but when I save one object of this class, no row is inserted in the table "resourceGroupHasResources" for the list of integers set. I have tried all combinations of cascade annotations.

¿Anyone can help me?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Persisting a @CollectionOfElements (List<Integer>)
PostPosted: Sat Aug 01, 2009 6:50 pm 
Newbie

Joined: Tue Jul 14, 2009 2:16 pm
Posts: 6
I'm not an expert, so take my advice with a grain of salt, but I can't figure out why you are using so many annotations. It seems to me like you definitely don't need all of that stuff. Look at this article: http://docs.jboss.org/hibernate/stable/ ... tions.html and then follow its guidance with annotations.

You might need to create another pojo, called "Property" or something, and then all you will need is the @OneToMany annotation on your collection. I'm sure there's a way to do it without creating another needless pojo, but I don't know it off the top of my head.


Top
 Profile  
 
 Post subject: Re: Persisting a @CollectionOfElements (List<Integer>)
PostPosted: Mon Aug 03, 2009 2:44 am 
Newbie

Joined: Fri Jul 31, 2009 12:09 pm
Posts: 2
Thanks for your reply dieter.law,

I know I may have too much annotations, I was trying different combinations and I wanted to show what I had already tried. Create another pojo can be a solution, but ¿do I need to create a table for this new pojo in my database schema then? Because all this comes when I wanted to map a list of integers, which reference no table in the schema.

I'm also sure there's a "cleaner" way to do it, but thank you for your advice.


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.