When used @Transactional
annotation in a method and we do not modify the domain object, still a new reference of the new object is committed.
For example lets take a sample case:
Domain Object:
@Table(name = "SAMPLE_TABLE")
public class SampleTable{
@Column(name = "ID")
String id;
@Column(name = "FIRST_NAME")
String firstName;
@Column(name = "CITY")
String city;
@Column(name = "STREET_ADDRESS")
private String streetAddress;
}
And I have a service method with @Transactional
annotation but doesn't modify the domain object.
@Transactional
public void doNothing(String id) {
SampleTable sampleTable = sampleTableRepository.findById(id);
}
So, whenever doNothing
method is executed, I see the domain object becomes dirty since a new reference with no change in data is committed.(Confirmed this using Hibernate Interception findDirty
method). When I remove the @Transactional
this(dirty object) doesn't happens.
Is this a normal behavior or a bug in Hibernate.