add, delete, recall no problem , but when they encounter problems updating it.
update processing is this:
1. Users send update requests to the Controller layer operation , Controller layer bound to the entity collecting data object (User)
2. call the Service layer method , the User object data binding just passed into
3. Dao layer method calls save , save.
Here is the problem : When modifying User information is automatically one of the many relationships associated List
I checked the search problem , because the User object when executed save, the object is not hosted by a state ( which is bound objects are automatically populated Controller ) resulting in a data set List
But the problem is not my own writing Dao layer is automatically generated by SpringDataJPA. It only provides a save method does not update methods. It stands to reason when executing the save method SpringData , it should be able to judge according to the state entity object is to perform the JPA persist () method is executed merge () method , but this seems to have always been executed persist () method , it has been regarded as a new operation to do .
I looked at the others to do the instance , but also to write the Controller of such entities , directly call Service, and then call the Dao update. In the middle there is no other operations ( such as once again find ), but others are very good, how would I have this problem too!
ask ah, this problem out for a whole day , the headache was dead
------ Solution --------------------- -----------------------
handy if he 's not , then package it themselves , before using hibernate when all save ago first merge what
------ Solution ------------------------------------- -------
save internally by the persist and merge support , has been called only persist, the object state is not saved , right?
------ Solution ------------------------------------ --------
you save the current object is not checked out by Dao Why ? That which does not contain List
------ For reference only -------------------------------------- -
spring data jpa feel is the heart of a white high ;
When I tested many association mapping , has also been the save () somehow made
In the same transaction , obviously one of the first save at one end , and then save the many side ,
is prompted org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing
But after the end of the first load save a little, and then save the many side together on smooth.
can not refer to pure JPA @ ManyToOne in Canada (cascade = {CascadeType.ALL})
otherwise end in a transaction end plus a few more will be repeated several times to insert a data
emergence of these troubles should be the landlord said spring data are internally save seems to have been executed persist () method
considered abandoned
------ For reference only ---------------------------------- -----
Spring Data JPA save operation is judged according to the state , if not through the process load of , Spring Data JPA think the object is free the state will perform the save operation ; If you need to update the property must be set before then Load Save this does little depressed , do not know if you have a good point method to solve this problem .
I looked under the Spring Data JPA for example , when doing an update operation for data transfer with the DTO objects when you save and then assigned to the Domain DTO object ..
------ For reference only ---------------------------------- -----
springdata download : http://www.zuidaima.com/share/search.htm?key=springdata
没有评论:
发表评论