Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Frits Walraven
  • Himai Minh

Stateful EJB - Excessive Queries

Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I have just started working with EJBs, so I don't know much about them, but doing a test a faced the following situation:

I have an entity named Product, that has an N:N relationship with one called Sector

in other words a Product can be sold in many Sectors and a Sector sells many Products

In my Product entity I have a list of Sectors, in a @OneToMany relationship.

And in my database I have 3 tables: Products, Sectors, and ProductSectors.

All the data from this relationship is persisted in the ProductSectors table

Well then, on to the issue: I have a product with 3 sectors in it's list, all already persisted in the database, now when I remove one sector from my list, and merge my Product, I saw that hibernate executed 3 queries

So as you can see, all the records were deleted, and then he inserted the other 2 again, is this behavior normal? Is there any way for me to change it via configuration or something else? So it will just delete the one Sector, with a single query?

Thank you all in advance!
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic