This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!