【发布时间】:2021-07-04 15:50:12
【问题描述】:
我试图只调用我的数据库中的特定列,但查询抛出一个错误,指出未找到下一列(即使它不在查询中)
执行此操作的连接有问题吗?我对这个问题有点困惑。
来自 ConnectionRequestRepository 的 JPA 查询 -
@Query(value = "SELECT connection_request.id, connection_request.userId, connection_request.dateTimeCompleted, connection_request.phoneNumber " +
"FROM ***.connection_request " +
"INNER JOIN ***.user " +
"ON ***.connection_request.userID = ***.user.id " +
"WHERE connection_request.dateTimeCompleted IS NULL " +
"LIMIT 1", nativeQuery = true)
ConnectionRequest findActiveRequest();
服务-
public ConnectionRequest getActiveRequestToCaller() {
return connectionRequestRepository.findActiveRequest();
}
控制器 -
ConnectionRequest currentLocationRequest = connectionRequestService.getActiveRequestToCaller();
ConnectionRequest 类 -
@Entity
@Table(name = "connection_request")
public class ConnectionRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
@NotNull
private Long id;
@Column(name = "userId")
@NotNull
private Long userId;
@Column(name = "uuid")
@NotNull
private UUID uuid;
@Column(name = "phoneNumber")
@NotNull
private String phoneNumber;
@Column(name = "locationSource")
@NotNull
private String locationSource;
@Column(name = "dateTimeRequested")
private Timestamp dateTimeRequested;
@Column(name = "dateTimeRequestExpires")
private Timestamp dateTimeRequestExpires;
@Column(name = "dateTimeCompleted")
private Timestamp dateTimeCompleted;
@Column(name = "s3Bucket")
private String s3Bucket;
@Column(name = "s3Key")
private String s3Key;
@Column(name = "s3Etag")
private String s3Etag;
@Column(name = "s3Sha256Hash")
private String s3Sha256Hash;
@Column(name = "isScheduledForCompletion")
@NotNull
private Integer isScheduledForCompletion;
public ConnectionRequest() {}
public ConnectionRequest(Long id,
Long userId,
UUID uuid,
String phoneNumber,
String locationSource,
Timestamp dateTimeRequested,
Timestamp dateTimeRequestExpires,
Timestamp dateTimeCompleted,
String s3Bucket,
String s3Key,
String s3Etag,
String s3Sha256Hash,
Integer isScheduledForCompletion) {
this.id = id;
this.userId = userId;
this.uuid = uuid;
this.phoneNumber = phoneNumber;
this.locationSource = locationSource;
this.dateTimeRequested = dateTimeRequested;
this.dateTimeRequestExpires = dateTimeRequestExpires;
this.dateTimeCompleted = dateTimeCompleted;
this.s3Bucket = s3Bucket;
this.s3Key = s3Key;
this.s3Etag = s3Etag;
this.s3Sha256Hash = s3Sha256Hash;
this.isScheduledForCompletion = isScheduledForCompletion;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getLocationSource() {
return locationSource;
}
public void setLocationSource(String locationSource) {
this.locationSource = locationSource;
}
public Timestamp getDateTimeRequested() {
return dateTimeRequested;
}
public void setDateTimeRequested(Timestamp dateTimeRequested) {
this.dateTimeRequested = dateTimeRequested;
}
public Timestamp getDateTimeRequestExpires() {
return dateTimeRequestExpires;
}
public void setDateTimeRequestExpires(Timestamp dateTimeRequestExpires) {
this.dateTimeRequestExpires = dateTimeRequestExpires;
}
public Timestamp getDateTimeCompleted() {
return dateTimeCompleted;
}
public void setDateTimeCompleted(Timestamp dateTimeCompleted) {
this.dateTimeCompleted = dateTimeCompleted;
}
public String getS3Bucket() {
return s3Bucket;
}
public void setS3Bucket(String s3Bucket) {
this.s3Bucket = s3Bucket;
}
public String getS3Key() {
return s3Key;
}
public void setS3Key(String s3Key) {
this.s3Key = s3Key;
}
public String getS3Etag() {
return s3Etag;
}
public void setS3Etag(String s3Etag) {
this.s3Etag = s3Etag;
}
public String getS3Sha256Hash() {
return s3Sha256Hash;
}
public void setS3Sha256Hash(String s3Sha256Hash) {
this.s3Sha256Hash = s3Sha256Hash;
}
public Integer getIsScheduledForCompletion() {
return isScheduledForCompletion;
}
public void setIsScheduledForCompletion(Integer isScheduledForCompletion) {
this.isScheduledForCompletion = isScheduledForCompletion;
}
}
【问题讨论】:
-
什么是
ConnectionRequest对象? -
@code_mechanic 这是数据库的名称。我是 JPA 查询的新手。我假设我写错了?
-
你将哪个类映射到 connection_request 表?
-
@MatheusCirillo 实体表(name = "connection_request") 公共类 ConnectionRequest
-
编辑问题并发布您的整个
ConnectionRequest课程。我认为问题是由于本机查询而发生的。所以,可以肯定的是,我必须看到ConnectionRequest类。 . .
标签: java mysql sql spring-boot jpa