【发布时间】:2012-01-03 16:15:32
【问题描述】:
经过多次搜索和试验,我被困住了......我有两个类,一个是 ExpectedSecurityReturn,另一个是 ForecastReturnType。 ForecastReturnType 是 ExpectedSecurityReturn 的成员,但不应在持久化数据时插入。我不断获得“权限不足”,但我知道用户确实拥有对表 expected_security_return 的删除/插入权限,因为我使用 JDBC 和 JPA 进行了测试,删除工作正常。因此,我认为这与我的课程有关。
@Table(name = "EXPECTED_SECURITY_RETURNS")
@Entity
@IdClass(ExpectedSecurityReturn.ExpectedSecurityReturnPK.class)
public class ExpectedSecurityReturn {
@Id
@Column(name = "REP_SEC_ID")
private Integer repSecId;
@Id
@Column(name = "AS_OF_DATE")
private Date date;
@Id
@ManyToOne(optional = false)
@JoinColumn(name = "RETURN_TYPE_ID", referencedColumnName = "RETURN_TYPE_ID", insertable=false)
private ForecastReturnType returnType;
@Column(name="CURR_TOUSD_RET") // local currency to usd
private Double currencyToUsdReturn;
}
主键类,其中包括 ForecastReturnType:
// ------------------------------
// PK
// ------------------------------
public static class ExpectedSecurityReturnPK implements Serializable {
private static final long serialVersionUID = 1325372032981567439L;
public ExpectedSecurityReturnPK() {
}
public ExpectedSecurityReturnPK(final Integer repSecId,
final Date asOfDate, ForecastReturnType returnType) {
if (repSecId == null)
throw new IllegalArgumentException("null rep sec id");
if (asOfDate == null)
throw new IllegalArgumentException("null asOfDate");
if (returnType == null)
throw new IllegalArgumentException("null returnType");
this.repSecId = repSecId;
this.date = new Date(asOfDate.getTime());
}
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
final ExpectedSecurityReturnPK that = (ExpectedSecurityReturnPK) o;
if (repSecId != that.repSecId)
return false;
if (!date.equals(that.date))
return false;
if (!returnType.equals(that.returnType))
return false;
return true;
}
@Override
public int hashCode() {
int result = repSecId;
result = 31 * result + date.hashCode();
result = 31 * result + returnType.getForecastTypeId();
return result;
}
private int repSecId;
private Date date;
private ForecastReturnType returnType;
}
和 ForecastReturnType:
@Table(name="EXPECTED_SEC_RET_TYPE_DECODE")
@Entity
public class ForecastReturnType {
@Id
@Column(name="RETURN_TYPE_ID")
private int forecastTypeId;
@Column(name="SHORT_NAME")
private String shortName;
@Column(name="LONG_NAME")
private String longName;
@OneToMany(fetch=FetchType.LAZY, mappedBy="returnType")
Collection<ExpectedSecurityReturn> expectedSecurityReturns;
}
谁能帮我弄清楚我做错了什么?我尝试了很多事情都没有成功......我认为罪魁祸首是 ExpectedSecurityReturn.returnType 因为我知道用户没有权限。
基本上,我需要插入/保留 ExpectedSecurityReturn 实例。
【问题讨论】:
-
在日志中查找 JPA 实现并告诉人们正在调用什么 SQL,以及异常的详细信息(及其堆栈跟踪)
-
其次,如果你使用的是 PostgreSQL,你可以改变 postgresql.conf(通常在 /var/pgsql 中)并在服务器上启用日志记录,寻找日志记录部分,通常有大量的 cmets 来帮助.如果您使用 MySQL,您可以在 my.cnf(通常在 /etc)中添加日志记录以记录所有查询,如果您使用 Oracle,您应该在 V$SQL 中看到它。我不太了解 MSSQL,不知道您是否可以记录所有查询,但我认为您可以通过 SQL Studio 获取数据库锁定的历史记录。
-
我看不出sql语句有什么问题,所以我认为它与包括外键在内的主键有关。不知何故,它需要对返回类型表拥有足够的权限)。插入SQL为:插入EXPECTED_SECURITY_RETURNS (CURR_TOUSD_RET, EXCESS_TOSECTOR_RET, EXCESS_TOTREAS_RET, LOCAL_RET, TREASURY_CARRY_RET, TREASURY_RET, AS_OF_DATE, REP_SEC_ID, RETURN_TYPE_ID)值(?, ?, ?, ?, ?, ?, ?, ?, ?)
标签: java jpa insert persistence jpa-2.0