java - spring-data detchated entity on child object -


Setting up the following tests using the Spring-Data CrudRepository

  @Test Public Zero Test CreateEventsThatShareallocation () {CreateFirstPlannedEvent (); CreateSecondPlannedEvent (); } @ Transactional Private Wide vs. Esconded Plan () {Planned Event Plan} = New planned adventure (); Location location = locationRepository.findByName (LOCATION_NAME); PlannedEvent.setLocation (location); PlannedEventRepository.save (plannedEvent); } @TransactionationPublicOndevelopedOfFirstPlanEvent () {Planned Avented PlanEvent = New planned adventure (); Location Locations = Place to Create (LOCATION_NAME); PlannedEvent.setLocation (location); PlannedEventRepository.save (plannedEvent); } Create public place Location (string name) {location location = new location (); Location.setName (name); Location.setSomeOtherStuff .... (); // does not call the method to save the repository of the location (no repository for location) return location; }   

When I run this test, I am getting it when the other is trying to store the planned hour:

 by  Reason: org.hibernate.PersistentObjectException: Separate when I debug through code, I think the first composition of the planned artist is cured, but it fails within the other.  

SimpleJpaRepository entityInformation.isNew (entity)

will be returned to the truth, and when trying Throw the above exception to save the other institution.

The fact is that it looks as a new unit is normal because this id value is empty.

I do not know how the place can be different since I am taking it before taking it into schematic application?

This can be done because both locations use a different example of repository and planned Entrepreneurship Unit Manager?

When I break into law and call it. Second planned appointment well, why is it?

Despite the fact that your methods have been annotated with the transaction, they are not.

Spring transactions are proxy-based, it means that the spring calls from one spring bean to another spring bean, thanks for the proxy, and initiates the transaction / this method of the second bean transaction is.

Can not call the Spring Method with an object. For this same object, you have a transaction for your call in fact for each call. That's why your place is different.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -