Java – optionally using cascading in Hibernate / JPA

My question is simple, but overall it's very important - I think I did research for hours, but I couldn't find anything useful

Introduction: I have an entity named employee - it is the central class of my system (such as its human resource management) Through the writing center, I think it has a lot to do with other members It contains the onetoone, onetomany and manytoone properties Problem: in some cases, I have to refresh this entity (it also has basic properties, such as' string name; ') – after changing in an entitymanager context (hibernate session), I have to refresh in other instances Of course I can use it:

entityManager.refreash(employee);

But... It will also refresh the entities related to "one hundred" (mentioned: 1-1, - 1,1-relationships), because these relationships have the annotation parameter cascade All or cascade REFREASH. Nothing is needed in that case - I only use the employee entity itself in this case What is unwanted, because it will hit the performance and even take 0.5 seconds locally... Question: is there a way to refresh the entity and optionally "close" the cascade of its attributes Perhaps: is there a way to refresh specific attributes of entities only using hibernate / JPA?

I really don't want hibernate to trigger those 20 longer SQL queries when I refresh my entities in those cases, but it is needed in other cases

In other words, I would say that I need options like "respectcascadesonrefresh = true / false", which can be set before refresh

Any other ideas?

Any help, appreciation,

Pedro

Solution

>First, if you refresh only two or three fields, use the standard API

PS: No, you can't use cascading manually because this annotation is used once when generating the database scheme

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>