-->
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.  [ 5 posts ] 
Author Message
 Post subject: Issue with negative primary key and many-to-many
PostPosted: Mon Mar 31, 2008 11:52 pm 
Newbie

Joined: Mon Mar 31, 2008 11:27 pm
Posts: 3
Hi,

I tried to find an answer in the forums, but had no luck.

I'm trying to use a negative integer for my primary keys (for data enter manually)

It works well eveywhere except when I have many-to-many associations. The code works fine since I hav ebeen using postive keys for a while and everything is fine

I'm using the annotations with EJB3/JPA.

When I run with a negative primary key, I get an index out of bounds because it looks like it's using the key to go into the list to build the objects.

Why does it use the ID/primary as the key for storing stuff in the list?

Here are my mappings:

Code:
@ManyToMany(fetch = FetchType.EAGER,
             targetEntity=Role.class)
    @JoinTable(name="user_role_mapping",
               joinColumns={@JoinColumn(name="user_id")},
               inverseJoinColumns={@JoinColumn(name="role_id")})
    private List<Role> userRoles;


Code:
@ManyToMany(fetch = FetchType.EAGER,
            mappedBy="userRoles",
            targetEntity=User.class)      
   @IndexColumn(name="mapping_id")
   private List<User> users = new ArrayList<User>(0);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 6:34 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Hibernate use index-column property for List elements. So your index-column "mapping_id" should non negative integer. or you can use Set insteadof List


Amila
(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 8:56 am 
Newbie

Joined: Mon Mar 31, 2008 11:27 pm
Posts: 3
I tried using a Set, but it still tried to do the same thing, so redargless of being a List or Set it still gave me an error. I will try again anyway to make sure.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 9:05 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

did you remove the @IndexColumn(name="mapping_id")


Amila
(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 11:56 pm 
Newbie

Joined: Mon Mar 31, 2008 11:27 pm
Posts: 3
Actually the Set was working. It was another ManyToMany down the line that was then giving an error and I thought it was the same one.

I can't go with a Set because I'm using Seam and it needs a List. I could convert Sets to List, but then I need to do major surgery with the code just to use the different IDs.

I decided to avoid negative IDs and use a larger ID for manually loaded data.

Thanks for the help


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