我试图用jpa运行一个应用程序,但我有下一个错误:
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [Oferta.findByLocalizacion: SELECT o FROM Oferta o WHERE o.negocioCif IN (SELECT cif FROM Negocio WHERE Direccion LIKE :direccion)], line 1, column 70: unexpected token [WHERE].
Internal Exception: NoViableAltException(79@[1327:1: subselectIdentificationVariableDeclaration[List varDecls] : ( identificationVariableDeclaration[varDecls] | n= associationPathExpression ( AS )? i= IDENT ( join )* | n= collectionMemberDeclaration );])
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:501)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:275)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:208)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:895)
at com.agrupadosobligatorio.persistencia.AbstractFacade.findRange(AbstractFacade.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
... 56 more
查询所在的文件就是这个:
@Entity
@Table(name = "oferta")
@XmlRootElement
@NamedQueries({
................
@NamedQuery(name = "Oferta.findByLocalizacion", query = "SELECT o FROM Oferta o WHERE o.negocioCif IN (SELECT cif FROM Negocio WHERE Direccion LIKE :direccion)"),
.........................})
public class Oferta implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idoferta")
private Integer idoferta;
@Basic(optional = false)
@NotNull
@Column(name = "fecha_inicio")
@Temporal(TemporalType.TIMESTAMP)
private Date fechaInicio;
@Basic(optional = false)
@NotNull
@Column(name = "fecha_fin")
@Temporal(TemporalType.TIMESTAMP)
private Date fechaFin;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 150)
@Column(name = "descripcion")
private String descripcion;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Basic(optional = false)
@NotNull
@Column(name = "precio_inicial")
private BigDecimal precioInicial;
@Basic(optional = false)
@NotNull
@Column(name = "precio_final")
private BigDecimal precioFinal;
@JoinColumn(name = "negocio_cif", referencedColumnName = "cif")
@ManyToOne(optional = false)
private Negocio negocioCif;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "ofertaIdoferta")
private Collection<Cupon> cuponCollection;
public Oferta() {
}
public Oferta(Integer idoferta) {
this.idoferta = idoferta;
}
public Oferta(Integer idoferta, Date fechaInicio, Date fechaFin, String descripcion, BigDecimal precioInicial, BigDecimal precioFinal) {
this.idoferta = idoferta;
this.fechaInicio = fechaInicio;
this.fechaFin = fechaFin;
this.descripcion = descripcion;
this.precioInicial = precioInicial;
this.precioFinal = precioFinal;
}
public Integer getIdoferta() {
return idoferta;
}
public void setIdoferta(Integer idoferta) {
this.idoferta = idoferta;
}
public Date getFechaInicio() {
return fechaInicio;
}
public void setFechaInicio(Date fechaInicio) {
this.fechaInicio = fechaInicio;
}
public Date getFechaFin() {
return fechaFin;
}
public void setFechaFin(Date fechaFin) {
this.fechaFin = fechaFin;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public BigDecimal getPrecioInicial() {
return precioInicial;
}
public void setPrecioInicial(BigDecimal precioInicial) {
this.precioInicial = precioInicial;
}
public BigDecimal getPrecioFinal() {
return precioFinal;
}
public void setPrecioFinal(BigDecimal precioFinal) {
this.precioFinal = precioFinal;
}
public Negocio getNegocioCif() {
return negocioCif;
}
public void setNegocioCif(Negocio negocioCif) {
this.negocioCif = negocioCif;
}
@XmlTransient
public Collection<Cupon> getCuponCollection() {
return cuponCollection;
}
public void setCuponCollection(Collection<Cupon> cuponCollection) {
this.cuponCollection = cuponCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idoferta != null ? idoferta.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Oferta)) {
return false;
}
Oferta other = (Oferta) object;
if ((this.idoferta == null && other.idoferta != null) || (this.idoferta != null && !this.idoferta.equals(other.idoferta))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.agrupadosobligatorio.bean.Oferta[ idoferta=" + idoferta + " ]";
}
}
所以你可以看到错误是在subselect上,我不知道如何解决它。拜托,你能帮帮我吗?。
非常感谢
答案 0 :(得分:0)
您在subselect中缺少Negocio实体名称,请尝试使用:
SELECT o FROM Oferta o WHERE o.negocioCif IN (SELECT cif FROM Negocio cif WHERE cif.Direccion LIKE :direccion)
或者您可以直接尝试:
SELECT o FROM Oferta o WHERE o.negocioCif.Direccion=:direccion