Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 265567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:46:53+00:00 2026-05-11T22:46:53+00:00

I have a JPA object which has a many-to-many relationship like this: @Entity public

  • 0

I have a JPA object which has a many-to-many relationship like this:

@Entity
public class Role {
    //...

    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(
    name="RolePrivilege",
    joinColumns=
        @JoinColumn(name="role", referencedColumnName="ID"),
    inverseJoinColumns=
        @JoinColumn(name="privilege", referencedColumnName="ID")
    )
    private Set<Privilege> privs;
}

There isn’t a JPA object for RolePrivilege, so I’m not sure how to write a JPQL query to delete entries from the privs field of a role object. For instance, I’ve tried this, but it doesn’t work. It complains that Role.privs is not mapped.

DELETE FROM Role.privs p WHERE p.id=:privId

I’m not sure what else to try. I could of course just write a native query which deletes from the join table RolePrivilege. But, I’m worried that doing so would interact badly with locally cached objects which wouldn’t be updated by the native query.

Is it even possible to write JPQL to remove entries from a join table like this? If not I can just load all the Role objects and remove entries from the privs collection of each one and then persist each role. But it seems silly to do that if a simple JPQL query will do it all at once.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:46:53+00:00Added an answer on May 11, 2026 at 10:46 pm

    The JPQL update and delete statements need to refer to an Entity name, not a table name, so I think you’re out of luck with the approach you’ve suggested.

    Depending on your JPA provider, you could delete the entries from the JoinTable using a simple raw SQL statement (should be 100% portable) and then programmatically interact with your cache provider API to evict the data. For instance in Hibernate you can call evict() to expire all “Role.privs” collections from the 2nd level cache:

    sessionFactory.evictCollection("Role.privs", roleId); //evict a particular collection of privs
    sessionFactory.evictCollection("Role.privs"); //evict all privs collections
    

    Unfortunately I don’t work with the JPA APIs enough to know for sure what exactly is supported.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPA entity similar to; public class Inventory { private String productname;
I have a problem with JPA 1.0 (OpenJPA) Following situation @Entity public class A{
I have a user object represented in JPA which has specific sub-types. Eg, think
I have a List of object, produced by JPA q.getResultList() . I would like
A have a JPA entity that has timestamp field and is distinguished by a
I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate) @Entity
HI, I have an object which has a piece of URL-Information associated with it.
Is it possible to have Spring inject the JPA entityManager object into my DAO
I have a JPA project and I would like to insert some initial data
I am learning JPA and have one question: In which situations we need more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.