I am trying to get an entry from the db.Change the value of one of the primary keys(outdt) and update it.Code below.I dont see any error on my console and db doesnt reflect the changes.Any insights would be appreciated!I have tried reading through jpa state documentation and detaching the entity before saving it back
`@Entity
@Table name='TestTable'
@Data
@NoArgsConstructor
@AllArgsConstructor
@Where(clause="END_DATE={ts '2025-03-01 00:00:00'}")
@IdClass(TestTablePk.class)
public class TestTable implements Serializable{
@Id
@Column("TEST_TABLE_ID",nullable=false)
@GeneratedValue(strategy=GenerationType.IDENTITY,generator="testTableseq")
@SequenceGenerator(name="testTableseq",schema="TEST",sequenceName="TEST_SEQ",allocationSize=1)
private Integer id;
@Id
@Column("END_DATE",nullable=false)
private Timestamp endDt;
//some more fields
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@Where(clause="end_date={ts '2025-03-01 00:00:00'}")
@IdClass(TestTablePk.class)
public class TestTablePk implements Serializable{
private Integer id;
private Timestamp endDt;`your text`
}
save code:
@Transactional
private saveCode(){
TestTable testObject=testRepository.findById(id);
entityManager.detach(testObject);
entityManager.setEndDt(Timestamp.valueOf(LocalDateTime.now()))
testRepository.save(testObject)
New contributor
unicorn12 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.