gpt4 book ai didi

java - QuerySyntaxException 但实体已映射

转载 作者:行者123 更新时间:2023-12-02 04:54:59 26 4
gpt4 key购买 nike

尝试从 Java 服务层进行简单的选择,这是我的模型:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="PROF_INFO")
public class ProfileInfo {

@EmbeddedId
private ProfileInfoPK profileInfoPK;

@Column(name="RATING", nullable = true )
private Integer rating;


@Column(name="VIEW_DATE", nullable = false )
private java.util.Date viewDate;


@Column(name="CONTACT_DATE", nullable = true )
private java.util.Date contactDate;


@Column(name="REPORTED_DATE", nullable = true )
private java.util.Date reportedDate;


@Column(name="REPORTED_TYPE", nullable = true )
private Integer reportedType;


@Column(name="REPORTED_COMMENT", nullable = true )
private String reportedComment;

public Integer getRating(){
return this.rating;
}
public void setRating(Integer rating){
this.rating = rating;
}

public java.util.Date getViewDate(){
return this.viewDate;
}
public void setViewDate(java.util.Date viewDate){
this.viewDate = viewDate;
}

public java.util.Date getContactDate(){
return this.contactDate;
}
public void setContactDate(java.util.Date contactDate){
this.contactDate = contactDate;
}

public java.util.Date getReportedDate(){
return this.reportedDate;
}
public void setReportedDate(java.util.Date reportedDate){
this.reportedDate = reportedDate;
}

public Integer getReportedType(){
return this.reportedType;
}
public void setReportedType(Integer reportedType){
this.reportedType = reportedType;
}

public String getReportedComment(){
return this.reportedComment;
}
public void setReportedComment(String reportedComment){
this.reportedComment = reportedComment;
}


@Embeddable
public static class ProfileInfoPK implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;


@Column(name="PST_USER_ID", nullable = false )
private Integer pstUserId;


@Column(name="FILE_NAME", nullable = false )
private String fileName;


public Integer getPstUserId() {
return pstUserId;
}


public void setPstUserId(Integer pstUserId) {
this.pstUserId = pstUserId;
}


public String getFileName() {
return fileName;
}


public void setFileName(String fileName) {
this.fileName = fileName;
}


@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((fileName == null) ? 0 : fileName.hashCode());
result = prime * result
+ ((pstUserId == null) ? 0 : pstUserId.hashCode());
return result;
}


@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProfileInfoPK other = (ProfileInfoPK) obj;
if (fileName == null) {
if (other.fileName != null)
return false;
} else if (!fileName.equals(other.fileName))
return false;
if (pstUserId == null) {
if (other.pstUserId != null)
return false;
} else if (!pstUserId.equals(other.pstUserId))
return false;
return true;
}



}


public ProfileInfoPK getProfileInfoPK() {
return profileInfoPK;
}
public void setProfileInfoPK(ProfileInfoPK profileInfoPK) {
this.profileInfoPK = profileInfoPK;
}

}

这是我的 DAOImpl:

public List<ProfileInfo> getByEntityandFileName(String entityId,
String fileName)throws NoSuchProfileInfoException , SystemException{
Query query = null;
List<ProfileInfo> results = null;
try{
query = sessionFactory.
getCurrentSession().
createQuery("from ProfileInfo where PST_USER_ID = :PST_USER_ID"); //AND FILE_NAME IN (:FILE_NAME)");
query.setParameter("PST_USER_ID", entityId);
//query.setParameterList("FILE_NAME", fileName.split("\\s*,\\s*"));
}catch(Exception ex){
throw new SystemException(ex);
}
if (query != null) {
results = query.list();
}else{
throw new SystemException("Query Null");
}

if (null != results && !results.isEmpty()) {
return results;
} else {
throw new NoSuchProfileInfoException("No Results Returned");
}
}

}

数据库在 PST_USER_ID、FILE_NAME 上具有 PK 索引 enter image description here

和描述

    desc PROF_INFO
Name Null Type
---------------- -------- --------------
PST_USER_ID NOT NULL NUMBER(38)
FILE_NAME NOT NULL VARCHAR2(32)
RATING NUMBER(38)
VIEW_DATE NOT NULL DATE
CONTACT_DATE DATE
REPORTED_DATE DATE
REPORTED_TYPE NUMBER
REPORTED_COMMENT VARCHAR2(1000)

一切看起来都很简单,但是当我尝试查询时,我收到以下错误:

org.hibernate.hql.internal.ast.QuerySyntaxException: ProfileInfo is not mapped [from ProfileInfo where PST_USER_ID = :PST_USER_ID]

不知道罪魁祸首是什么,但左边有东西。你们觉得有什么地方不合适吗?

最佳答案

您将 pur SQL 与 HQL 混合在一起。应该是

createQuery("from ProfileInfo where profileInfoPK.pstUserId = :PST_USER_ID");

检查profileInfoPK.pstUserId部分。

关于java - QuerySyntaxException 但实体已映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com