大佬教程收集整理的这篇文章主要介绍了当我使用按查询查找时,spring boot jpa 正在更新我的数据库,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是所有 3 个实体的代码。
每当我制作 repo.findByUserJavaIDAndCohortIDAndStatusInorderByLASTUPDATEDDesc()
这也会更新我数据库中的 last_updated
列。
public abstract class BaseEntity {
@ID
@GeneratedValue(strategy = GenerationType.IDENTITY)
@column(unique = truE)
protected Long ID;
@column(unique = true,updatable = false,nullable = falsE)
protected UUID uuID;
@Builder.Default
@column(name = "is_deleted",nullable = false,columnDeFinition = "bool default false")
@JsonIgnore
protected Boolean isdeleted=false;
@column(name = "created",updatable = falsE)
@Creationtimestamp
@JsonIgnore
@datetiR_242_11845@eFormat(iso = datetiR_242_11845@eFormat.ISO.date_time)
protected date created;
@column(name = "last_updated",nullable = falsE)
@updatetimestamp
@JsonIgnore
@datetiR_242_11845@eFormat(iso = datetiR_242_11845@eFormat.ISO.date_time)
protected date LASTUPDATED;
public BaseEntity() {
thiS.UuID = UUID.randomUUID();
this.isdeleted = false;
}
}
@table(name = "task")
public class Task extends BaseEntity {
@NotNull
@column(nullable = falsE)
private String title;
@NotNull
@column(nullable = falsE)
@Enumerated(EnumType.StriNG)
private source source;
@NotNull
@column(name="remote_ID",nullable = falsE)
@JsonIgnore
private String remotEID;
@NotNull
@column(name = "cohort_ID",nullable = falsE)
private Long cohortID;
@Builder.Default
@column(nullable = falsE)
@Enumerated(EnumType.StriNG)
@NotNull
private TaskState state = TaskState.UPCOMING;
@column(nullable = falsE)
@Enumerated(EnumType.StriNG)
@NotNull
private EventType type;
@NotNull
@Length(max = 5000)
@column(nullable = false,columnDeFinition ="LONGTEXT" )
private String agenda;
@Type(type = "TaskExTradataType")
@column(name = "extra_data",columnDeFinition = "Jsonb")
private TaskExTradata exTradata;
@column(name = "schedule_time")
@datetiR_242_11845@eFormat(iso = datetiR_242_11845@eFormat.ISO.date_time)
protected date scheduleTime;
@column(name = "start_time")
@datetiR_242_11845@eFormat(iso = datetiR_242_11845@eFormat.ISO.date_time)
protected date startTime;
@column(name = "end_time")
@datetiR_242_11845@eFormat(iso = datetiR_242_11845@eFormat.ISO.date_time)
protected date endTime;
}
@table(name = "user_task",public class UserTask extends BaseEntity {
@manyToOne
@Joincolumn(name = "task_ID")
Task task;
@NotNull
@column(name = "user_java_ID",nullable = falsE)
Long userJavaID;
@NotNull
@column(name = "cohort_ID",nullable = falsE)
private Long cohortID;
@Builder.Default
@column(nullable = falsE)
@Enumerated(EnumType.StriNG)
UserTaskStatus status = UserTaskStatus.PENDING;
@Type(type = "UserTaskExTradataType")
@column(name = "extra_data",columnDeFinition = "Jsonb")
private UserTaskExTradata userTaskExTradata;
}
public interface UserTaskRepository extends JpaRepository<UserTask,Long> {
List<UserTask> findByUserJavaIDAndCohortIDAndStatusInorderByLASTUPDATEDDesc(long userJavaID,long cohortID,List<UserTaskStatus> status);
}
Hibernate 调用 equals 方法检查对象是否已更改,然后调用深拷贝方法获取自定义对象的副本。所以我在额外的类中添加了 equals 方法,它完美地工作。
public class UserTaskExtraData implements serializable {
private Integer timeSpenTinR_242_11845@ins;
@Override
public Boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserTaskExtraData that = (UserTaskExtraData) o;
return Objects.equals(timeSpenTinR_242_11845@ins,that.timeSpenTinR_242_11845@ins);
}
@Override
public int hashCode() {
return Objects.hash(timeSpenTinR_242_11845@ins);
}
}
public class TaskExtraData implements serializable {
private String link;
private String expertName;
private Long expertId;
private String expertImageUrl;
private String eventImageUrl;
private double duration;
private String expertEmail;
@Override
public Boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TaskExtraData that = (TaskExtraData) o;
return Double.compare(that.duration,duration) == 0 && Objects.equals(link,that.link) && Objects.equals(expertName,that.expertName) && Objects.equals(expertId,that.expertId) && Objects.equals(expertImageUrl,that.expertImageUrl) && Objects.equals(eventImageUrl,that.eventImageUrl) && Objects.equals(expertEmail,that.expertEmail);
}
@Override
public int hashCode() {
return Objects.hash(link,expertName,expertId,expertImageUrl,eventImageUrl,duration,expertEmail);
}
}
以上是大佬教程为你收集整理的当我使用按查询查找时,spring boot jpa 正在更新我的数据库全部内容,希望文章能够帮你解决当我使用按查询查找时,spring boot jpa 正在更新我的数据库所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。