I’m trying to exclude the unchanged BLOB column from generated update statement. My simplified entity with the @DynamicUpdate annotation is as follows:
@Entity
@DynamicUpdate
public class Part {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PartSequence")
@SequenceGenerator(name = "PartSequence", sequenceName = "part_seq", allocationSize = 1)
@Column(name = "id")
private Long id;
public Long getId() {
return this.id;
}
public Part setId(Long id) {
this.id = id;
return this;
}
@Column(name = "part_number")
private Integer partNumber;
public Integer getPartNumber() {
return this.partNumber;
}
public Part setPartNumber(Integer partNumber) {
this.partNumber = partNumber;
return this;
}
@Column(name = "create_datetime")
private LocalDateTime createDateTime;
public LocalDateTime getCreateDateTime() {
return this.createDateTime;
}
public Part setCreateDateTime(LocalDateTime createDateTime) {
this.createDateTime = createDateTime;
return this;
}
@Lob
@Column(name = "content", columnDefinition = "blob")
private Blob content;
public Blob getContent() {
return this.content;
}
public Part setContent(Blob content) {
this.content = content;
return this;
}
@Version
@Column(name = "version")
private Long version;
}
The corresponding JPA repository implementation is below:
@Repository
public interface PartRepository extends JpaRepository<Part, Long> { }
and the snippet of test code:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExtraupdateApplicationTests {
@Autowired
private PartRepository partRepository;
@Test
public void testExtraUpdate() {
Part part = this.partRepository.save(new Part());
part.setPartNumber(1);
part = this.partRepository.save(part); //1
byte[] bytes = new byte[4096];
new Random().nextBytes(bytes);
part.setContent(BlobProxy.generateProxy(bytes));
part = this.partRepository.save(part); //2
part.setCreateDateTime(LocalDateTime.now());
part = this.partRepository.save(part); //3
}
}
Only changed columns are included in the generated update statements in the lines //1 and //2. In the //3 line only the CREATE_DATETIME column is changed, but the CONTENT column is surprisingly also included in the update statement.
org.hibernate.SQL : update part set part_number=?, version=? where id=? and version=? //1
...
org.hibernate.SQL : update part set version=?, content=? where id=? and version=? //2
...
org.hibernate.SQL : update part set create_datetime=?, version=?, content=? where id=? and version=? //3
How to get rid of the unnecessary CONTENT column in the //3 update statement?
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1.0</version>
</dependency>
</dependencies>
</project>