1

JSF 2.0、Primefaces 3.4、Oracle、NetBeans 7.2.1 を使用していますが、次のエラーが発生しました。

ADVERTENCIA: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
Error Code: 936
Call: SELECT t1.OPT_ID, t1.OPT_ANT_FM_DET FROM SAE_PACIENTE t0, SAE_OPTOMETRIA t1 WHERE ((((t0.P_ID = ) AND (t0.P_IDENTIFICACION = ?)) AND (t0.P_TIPO_IDENTIFICACION = ?)) AND (t0.P_ID = t1.OPT_P_ID))

SaeOptometria と SaePaciente の 2 つの豆があります。SaeOPtometria には、SaePaciente Bean との関係である次の属性があります。

@JoinColumn(name = "OPT_P_ID", referencedColumnName = "P_ID")
@ManyToOne
private SaePaciente optPId;

また、次の名前付きクエリもあります。

@NamedQuery(name = "SaeOptometria.findByPaciente", query = "SELECT s FROM SaeOptometria s INNER JOIN s.optPId d WHERE d.pId=s.optPId AND d.pIdentificacion = :pIdentificacion AND d.pTipoIdentificacion = :pTIdentificacion"),

次のコードを使用して、パラメーター :pIdentificacion および :pTIdentificacion を SaeOptometriaFacade ファイルに渡しています。

public List<SaeOptometria> consultaporIdYTI(String UIpIdentificacion, String UIpTipoIdentificacion){

    Query query= em.createNamedQuery("SaeOptometria.findByPaciente");
    query.setParameter("pIdentificacion", UIpIdentificacion);
    query.setParameter("pTIdentificacion", UIpTipoIdentificacion);
    List<SaeOptometria> SaeOptometriaList= query.getResultList();
    return SaeOptometriaList;
}

NamedQuery のパラメーター pIdentificacion と pTipoIdentificacion が SaePaciente Bean に属していることを明確にしました。

@Id
@SequenceGenerator(name="SEQ1",sequenceName = "SAE_AINCR_PACIENTE",allocationSize=1)  
@GeneratedValue(strategy=GenerationType.IDENTITY, generator="SEQ1")
@Basic(optional = false)
@NotNull
@Column(name = "P_ID")
private Integer pId;
@Size(max = 15)
@Column(name = "P_IDENTIFICACION")
private String pIdentificacion;
@Size(max = 20)
@Column(name = "P_TIPO_IDENTIFICACION")
private String pTipoIdentificacion;

なぜ機能しないのですか?

ありがとう。

4

1 に答える 1

2

あなたのクエリは間違っているようです:

SELECT s FROM SaeOptometria s INNER JOIN s.optPId d WHERE d.pId=s.optPId AND d.pIdentificacion = :pIdentificacion AND d.pTipoIdentificacion = :pTIdentificacion

FROM SaeOptometria の INNER JOIN TO_WHAT

あなたのコメントの後、私は私の最初の理解が間違っていると判断しました. FROM 句と from WHERE 句の両方で結合します。そのうちの 1 つだけを実行してみてください。

次のクエリを試して、結果を報告していただけますか:

1 つ目: Join は JPA によって提供されます。ID を明示的に提供しない。この情報は、JPA マッピングで指定する必要があります

SELECT s FROM SaeOptometria s INNER JOIN s.optPId d WHERE d.pIdentificacion = :pIdentificacion AND d.pTipoIdentificacion = :pTIdentificacion

2 つ目: 明示的に参加します。テーブルを指定し、ID 値を明示的に指定して結合します。

SELECT s FROM SaeOptometria s WHERE s.optPId.pId=s.optPId and s.optPId.pIdentificacion = :pIdentificacion AND s.optPId.pTipoIdentificacion = :pTIdentificacion
于 2013-03-31T07:03:26.327 に答える