-->
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.  [ 2 posts ] 
Author Message
 Post subject: object handling using mapping tables
PostPosted: Fri Jun 18, 2010 5:27 pm 
Newbie

Joined: Fri Jun 18, 2010 5:15 pm
Posts: 3
Hi,

I just started using Hibernate with JPA 2 but I'm still having some problems understanding the fundamentals.
Let's say I have 2 Classes:

@Entity
class User

@Entity
class Permission

I connect the two via a mapping-table "user_permission" which references the user_id and permission_id from the main-tables.
Whenever I want to delete a Permission from a User I cannot delete the Permission from the User-object because
then a Row would be deleted from the "permission" table.
Instead I have to delete it from the mapping-table "user_permission".
What would be the best way to do this in Hibernate/JPA?
Are there any annotations available for such a Usecase or do I have to use a Query from the EnityManager here:
Code:
em.createQuery("DELETE FROM user_permission WHERE user_id = :userid AND permission_id = :permission_id")


Thanks in advance, getagrip


Top
 Profile  
 
 Post subject: Re: object handling using mapping tables
PostPosted: Fri Jun 18, 2010 6:19 pm 
Newbie

Joined: Fri Jun 18, 2010 5:15 pm
Posts: 3
Using a Query via the EnityManager throws the following Exception:

QuerySyntaxException: user_permission is not mapped.

So the mapping-table "user_permission" is not mapped. Why would I want to map a cross-reference-table anyway? This does not make sense at all.

Somehow I believe there must be another way to manage this correctly.
Any hints?


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