• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateful EJB - Excessive Queries

Rodrigo Sasaki
Posts: 24
  • Mark post as helpful
  • send pies
  • 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!
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!