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 8470781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:36:58+00:00 2026-06-10T16:36:58+00:00

i have two entities Customer and Order (trivial setters and getters excluded) @Entity public

  • 0

i have two entities Customer and Order (trivial setters and getters excluded)

@Entity
public class Customer {

    @GeneratedValue
    @Id
    private int id;

    @OneToMany
    List<Order> orderList;


}

@Entity
public class Order {

    @GeneratedValue
    @Id
    private int id;

    @ManyToOne
    Customer customer;

    private boolean paid;

    public Order(Customer customer) {

        this.customer = customer;
        customer.getOrderList().add(this)
    }   
}

Now i want to set ‘paid = true’ for all the orders of a given customer
Below query seem to do the trick, but I get a feeling it is innefficient and the fact that i stored the reverse relationship in Customer.orderList hints that there should be some other way to do this.

UPDATE Order o SET o.paid = true WHERE EXISTS 
(SELECT c.orderList FROM Customer c WHERE o MEMBER OF c.orderList AND c = :customer)

I’m using container managed transactions, glassfish and javaDb. But I’d prefer if improvements could be done in JPA/JPQL domain and not specific to container or db.

  • 1 1 Answer
  • 0 Views
  • 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-06-10T16:37:00+00:00Added an answer on June 10, 2026 at 4:37 pm

    private id; ?? missed field type

    Add to @OneToMany annotation,cascade = CascadeType.All

    Customer entity = entityManager.find(Customer.class, id)   
    for (Order order : entity.getOrderList())  
    {
       order.setPaid(true);  
    }  
    

    if you are using cantainer managed transaction then true will be saved to DB

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

Sidebar

Related Questions

I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities like this: public class Service { public virtual int ServiceId
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities like public class Person { public int PersonId { get;
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities say Customer and Order which exist on their own and
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two entities, Customer and Order, both of which I have created types
I have a two entities that are related like so. public class User {

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.