• 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
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin

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!
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic