2014-09-07 2 views
0

Я пытаюсь запустить приложение с JPA, но у меня есть следующая ошибка:подзапросы в 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([email protected][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 + " ]"; 
} 

}

Итак, вы можете видеть, что ошибка находится в подзапросе, и я не знаю, как ее решить. Пожалуйста, не могли бы вы мне помочь?

Большое спасибо

ответ

0

Вы пропускаете 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