我正在使用JPA 2.0,Eclipselink 2.0,maven和weblogic 10.3.6。这是我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="certifications" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/com/ni/ds_edata_soa_nontx</jta-data-source>
<class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStg</class>
<class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStgPK</class>
<class>com.ni.apps.engineering.certification.entities.NicdsCliUpMapping</class>
<properties>
<property name="javax.persistence.jdbc.password" value="ni"/>
<property name="javax.persistence.jdbc.user" value="NI"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
</properties>
</persistence-unit>
</persistence>
这是我的门面
package com.ni.apps.engineering.certification.controller;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUnit;
import javax.persistence.TypedQuery;
import com.ni.apps.engineering.certification.entities.NicdsCliCertificationStg;
import com.ni.apps.engineering.certification.exception.CertificationException;
import com.ni.apps.engineering.certification.utils.CertificationConstants;
public class CertificationFacade {
@PersistenceUnit(unitName = "certifications")
private EntityManagerFactory emf;
public List<NicdsCliCertificationStg> getCertificationsByUpId(String upId)
throws CertificationException {
String stringQuery = new StringBuilder(
"select c from NicdsCliCertificationStg c where c.id.contactsId = 1234").toString();
//.append(upId).toString();
try {
emf = Persistence.createEntityManagerFactory("certifications");
EntityManager em = emf.createEntityManager();
TypedQuery<NicdsCliCertificationStg> query = em
.createQuery(stringQuery, NicdsCliCertificationStg.class);
return query.getResultList();
} catch (Exception e) {
throw new CertificationException(
CertificationConstants.INTERNAL_ERROR_MESSAGE, e);
}
}
}
当我尝试运行应用时,这就是我得到的错误
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
Error Code: 942
Call: SELECT CONTACTS_ID, PROFILE_ID FROM NI.NICDS_CLI_UP_MAPPING WHERE (PROFILE_ID = ?)
bind => [1 parameter bound]
Query: ReadAllQuery(referenceClass=NicdsCliUpMapping sql="SELECT CONTACTS_ID, PROFILE_ID FROM NI.NICDS_CLI_UP_MAPPING WHERE (PROFILE_ID = ?)")
为什么它无法找到表格?
CNC中 添加实体
package com.ni.apps.engineering.certification.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
/**
* The persistent class for the NICDS_CLI_CERTIFICATION_STG database table.
*
*/
@Entity
@Table(name="NICDS_CLI_CERTIFICATION_STG", schema="NI")
public class NicdsCliCertificationStg implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private NicdsCliCertificationStgPK id;
@Column(name="ALTERNATE_EMAIL")
private String alternateEmail;
@Temporal(TemporalType.DATE)
@Column(name="CERT_EXPIRATION_DATE")
private Date certExpirationDate;
@Temporal(TemporalType.DATE)
@Column(name="CERT_ISSUE_DATE")
private Date certIssueDate;
@Column(name="CERT_STATUS")
private String certStatus;
@Column(name="FIRST_NAME")
private String firstName;
@Column(name="LAST_NAME")
private String lastName;
@Column(name="PRIMARY_EMAIL")
private String primaryEmail;
//bi-directional one-to-one association to NicdsCliUpMapping
@OneToOne
@JoinColumn(name="CONTACTS_ID")
private NicdsCliUpMapping nicdsCliUpMapping;
public NicdsCliCertificationStg() {
}
public NicdsCliCertificationStgPK getId() {
return this.id;
}
public void setId(NicdsCliCertificationStgPK id) {
this.id = id;
}
public String getAlternateEmail() {
return this.alternateEmail;
}
public void setAlternateEmail(String alternateEmail) {
this.alternateEmail = alternateEmail;
}
public Date getCertExpirationDate() {
return this.certExpirationDate;
}
public void setCertExpirationDate(Date certExpirationDate) {
this.certExpirationDate = certExpirationDate;
}
public Date getCertIssueDate() {
return this.certIssueDate;
}
public void setCertIssueDate(Date certIssueDate) {
this.certIssueDate = certIssueDate;
}
public String getCertStatus() {
return this.certStatus;
}
public void setCertStatus(String certStatus) {
this.certStatus = certStatus;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPrimaryEmail() {
return this.primaryEmail;
}
public void setPrimaryEmail(String primaryEmail) {
this.primaryEmail = primaryEmail;
}
public NicdsCliUpMapping getNicdsCliUpMapping() {
return this.nicdsCliUpMapping;
}
public void setNicdsCliUpMapping(NicdsCliUpMapping nicdsCliUpMapping) {
this.nicdsCliUpMapping = nicdsCliUpMapping;
}
}
package com.ni.apps.engineering.certification.entities;
import java.io.Serializable;
import javax.persistence.*;
/**
* The primary key class for the NICDS_CLI_CERTIFICATION_STG database table.
*
*/
@Embeddable
public class NicdsCliCertificationStgPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(name="CONTACTS_ID")
private long contactsId;
@Column(name="CERT_NAME")
private String certName;
public NicdsCliCertificationStgPK() {
}
public long getContactsId() {
return this.contactsId;
}
public void setContactsId(long contactsId) {
this.contactsId = contactsId;
}
public String getCertName() {
return this.certName;
}
public void setCertName(String certName) {
this.certName = certName;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof NicdsCliCertificationStgPK)) {
return false;
}
NicdsCliCertificationStgPK castOther = (NicdsCliCertificationStgPK)other;
return
(this.contactsId == castOther.contactsId)
&& this.certName.equals(castOther.certName);
}
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + ((int) (this.contactsId ^ (this.contactsId >>> 32)));
hash = hash * prime + this.certName.hashCode();
return hash;
}
}
package com.ni.apps.engineering.certification.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
/**
* The persistent class for the NICDS_CLI_UP_MAPPING database table.
*
*/
@Entity
@Table(name="NICDS_CLI_UP_MAPPING", schema="NI")
public class NicdsCliUpMapping implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="NICDS_CLI_UP_MAPPING_CONTACTSID_GENERATOR" )
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="NICDS_CLI_UP_MAPPING_CONTACTSID_GENERATOR")
@Column(name="CONTACTS_ID")
private long contactsId;
@Column(name="PROFILE_ID")
private BigDecimal profileId;
//bi-directional one-to-one association to NicdsCliCertificationStg
@OneToOne(mappedBy="nicdsCliUpMapping")
private NicdsCliCertificationStg nicdsCliCertificationStg;
public NicdsCliUpMapping() {
}
public long getContactsId() {
return this.contactsId;
}
public void setContactsId(long contactsId) {
this.contactsId = contactsId;
}
public BigDecimal getProfileId() {
return this.profileId;
}
public void setProfileId(BigDecimal profileId) {
this.profileId = profileId;
}
public NicdsCliCertificationStg getNicdsCliCertificationStg() {
return this.nicdsCliCertificationStg;
}
public void setNicdsCliCertificationStg(NicdsCliCertificationStg nicdsCliCertificationStg) {
this.nicdsCliCertificationStg = nicdsCliCertificationStg;
}
}
答案 0 :(得分:0)
错误是weblogic的数据源具有与应用程序架构所需的用户和密码不同的组合。如果我找到一种方法强制JPA使用特定架构/用户/密码组合而不更改数据源中的用户,我将更新此答案。
答案 1 :(得分:0)
如果您使用其他用户进行测试,则使用在数据源中配置的用户
在数据源连接池配置中,转到高级部分
在“Init SQL”部分中键入此内容(请参阅指令前面的SQL字,需要它)
SQL ALTER SESSION SET CURRENT_SCHEMA = DEVLPMT
请参阅http://docs.oracle.com/middleware/1212/wls/JDBCA/jdbc_datasources.htm#CJAFCBBD