• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why EntityManager.refresh, and EntityManager.remove require attached entity?

 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't they make the entity be attached if needed? Is there any design issues prevent that?

I think it doesn't make sense that if I want to refresh, or remove I need to merge first, and merging is updating, right?
Moreover, I think it's very confusing that to refresh or remove I need to call merge *to update the entity first*( before I can refresh (reset) or remove it.

There is no point to merge (update) if I want to refresh or remove an entity.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for entitymanager.refresh, you can retached an entity which was detached

for entitymanger.remove, you have to make sure the entity must be attached before you remove it
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why don't they make the entity be attached if needed? Is there any design issues prevent that?


It won't be tough for container provider to implement it. But container provider (entity manager implementor) need to follow what spec says to them.

I think it doesn't make sense that if I want to refresh, or remove I need to merge first, and merging is updating, right? Moreover, I think it's very confusing that to refresh or remove I need to call merge *to update the entity first*( before I can refresh (reset) or remove it.
There is no point to merge (update) if I want to refresh or remove an entity.


I had same doubt in this thread, and I was answer by Ralph Jaus that requirement is entity should be attached before refresh/ remove is called and that is possible by calling find() before refresh/ remove is called
em.refresh(em.find(Item.class, item.id));




 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jim li wrote:for entitymanager.refresh, you can retached an entity which was detached

for entitymanger.remove, you have to make sure the entity must be attached before you remove it


I know, jim, and my question is "why"
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepika Joshi wrote:

Why don't they make the entity be attached if needed? Is there any design issues prevent that?


It won't be tough for container provider to implement it. But container provider (entity manager implementor) need to follow what spec says to them.


I think it's easy to implement, but is this a problem in JPA spec or there is a merit behind these awkward to use API?
If this is a problem in the spec, is there a plan to improve in the next version?

Deepika Joshi wrote:

I think it doesn't make sense that if I want to refresh, or remove I need to merge first, and merging is updating, right? Moreover, I think it's very confusing that to refresh or remove I need to call merge *to update the entity first*( before I can refresh (reset) or remove it.
There is no point to merge (update) if I want to refresh or remove an entity.


I had same doubt in this thread, and I was answer by Ralph Jaus that requirement is entity should be attached before refresh/ remove is called and that is possible by calling find() before refresh/ remove is called
em.refresh(em.find(Item.class, item.id));


Thanks, but I am still not satisfied, because I think it should be like em.fresh(item), em.remove(item)
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic