gpt4 book ai didi

java - JPA - SQLException创建记录

转载 作者:行者123 更新时间:2023-12-02 05:41:25 24 4
gpt4 key购买 nike

我已从数据库导入此实体类(使用 Netbeans 功能 - 数据库中的实体类)。

不幸的是我无法让它工作。

IMS_MEASUREMENTS 表

INSTALLED_IMS_ID - NUMBER(9)
MEASUREMENT_IMS_ORD - NUMBER(9)
MEASUREMENT_TYPE_ID - NUMBER(9)
DEVICE_ID - NUMBER(9)
MEASUREMENT_TIME - TIMESTAMP(3)
MEASUREMENT_VALUE - NUMBER(9,2)
MEASUREMENT_MAX_VALUE - NUMBER(9,2)
MEASUREMENT_MIN_VALUE - NUMBER(9,2)
NOTES - VARCHAR(255 BYTE)
PREVIOUS_INFO - NUMBER(5)
LAST_UPDATE - TIMESTAMP(3)
MEASUREMENT_PRECISION - NUMBER(2)
LOCALIZATION_ID - NUMBER(9)

主键是(INSTALLED_IMS_ID、MEASUREMENT_IMS_ORD)

ImsMeasurements.java

@Entity
public class ImsMeasurements implements Serializable {
@EmbeddedId
protected ImsMeasurementsPK imsMeasurementsPK;

@Column(name = "MEASUREMENT_TYPE_ID")
private Integer measurementTypeId;
@Basic(optional = false)
@Column(name = "MEASUREMENT_TIME")
@Temporal(TemporalType.TIMESTAMP)
private Date measurementTime;
@Column(name = "MEASUREMENT_VALUE")
private BigDecimal measurementValue;
@Column(name = "MEASUREMENT_MAX_VALUE")
private BigDecimal measurementMaxValue;
@Column(name = "MEASUREMENT_MIN_VALUE")
private BigDecimal measurementMinValue;
@Column(name = "NOTES")
private String notes;
@Column(name = "PREVIOUS_INFO")
private Integer previousInfo;
@Column(name = "LAST_UPDATE")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate;
@Column(name = "MEASUREMENT_PRECISION")
private Short measurementPrecision;
@Column(name = "LOCALIZATION_ID")
private Integer localizationId;
....
....

//constructors
public ImsMeasurements() {
}

public ImsMeasurements(ImsMeasurementsPK imsMeasurementsPK) {
this.imsMeasurementsPK = imsMeasurementsPK;
}

public ImsMeasurements(ImsMeasurementsPK imsMeasurementsPK, Date measurementTime) {
this.imsMeasurementsPK = imsMeasurementsPK;
this.measurementTime = measurementTime;
}

public ImsMeasurements(int installedImsId, int measurementImsOrd) {
this.imsMeasurementsPK = new ImsMeasurementsPK(installedImsId, measurementImsOrd);
}
}

ImsMeasurementsPK.java

@Embeddable
public class ImsMeasurementsPK implements Serializable {
@Basic(optional = false)
@Column(name = "INSTALLED_IMS_ID")
private int installedImsId;

@Basic(optional = false)
@Column(name = "MEASUREMENT_IMS_ORD")
private int measurementImsOrd;
....

//constructors
public ImsMeasurementsPK() {
}

public ImsMeasurementsPK(int installedImsId, int measurementImsOrd) {
this.installedImsId = installedImsId;
this.measurementImsOrd = measurementImsOrd;
}
}

设置测量

//setting measure primary key    
ImsMeasurements mis = new ImsMeasurements(new ImsMeasurementsPK(1, 1));
....

坚持它。

em.persist(mis);

我发现这种java.sql.SQLException:ORA-01438:值大于此列允许的指定精度

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-01438: value larger than specified precision allowed for this column

Error Code: 1438
Call: INSERT INTO SICURFER.IMS_MEASUREMENTS (LAST_UPDATE, LOCALIZATION_ID, MEASUREMENT_MAX_VALUE, MEASUREMENT_MIN_VALUE, MEASUREMENT_PRECISION, MEASUREMENT_TIME, MEASUREMENT_TYPE_ID, MEASUREMENT_VALUE, NOTES, PREVIOUS_INFO, MEASUREMENT_IMS_ORD, INSTALLED_IMS_ID, DEVICE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [13 parameters bound]
Query: InsertObjectQuery(com.ansaldosts.sic.dao.ImsMeasurements[ imsMeasurementsPK=com.ansaldosts.sic.dao.ImsMeasurementsPK[ installedImsId=1, measurementImsOrd=1 ] ])

JPA 提供程序 -> EclipseLink,版本:Eclipse Persistence Services - 2.2.0.v20110202-r8913

我尝试插入的值:

mis.setMeasurementValue(BigDecimal.valueOf(110));
mis.setMeasurementTypeId(10);
String s = "2014-04-17 12:05:00";
Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ITALY).parse(s);
mis.setMeasurementTime(date);
mis.setMeasurementPrecision(Short.MIN_VALUE);
mis.setMeasurementMinValue(BigDecimal.ZERO);
mis.setMeasurementMaxValue(BigDecimal.ZERO);
mis.setLocalizationId(Integer.valueOf(10));
mis.setDeviceId(2);
mis.setImsSystems(110);

问题出在哪里,我错在哪里?

提前致谢,弗朗西斯科

最佳答案

有三个字段使用“BigDecimal”类型,该类型可能会变大。您需要检查数据库中每一列的类型。

关于java - JPA - SQLException创建记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24485070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com