我整个下午都在看这个,我很难过。为什么 EclipseLink 使用重复值?怎么可能?
这个实体类使用 Hibernate 运行良好,但我试图让应用程序在 Glassfish 3.1.2.2 下运行。
应用程序失败并显示:
[#|2013-11-04T15:54:17.190-0700|WARNING|glassfish3.1.2|org.eclipse.persistence.session.file:/C:/glassfish3/glassfish/domains/domain1/applications/foo_jar/_bar.sql|_ThreadID=143;_ThreadName=Thread-2;|Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (GAPM.SYS_C0033927) violated
Error Code: 1
Call: INSERT INTO TIME_DIMENSION (ID, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, JWK_WEEK, JWK_YEAR, MINUTE, MONTH, MONTH_NAME, QUARTER, WEEKDAY, YEAR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [3565649, 4, 1, 308, 19, 45, 2013, 7, 11, November, 2, Monday, 2013]
Query: InsertObjectQuery(com.germainsoftware.apm.model.TimeDimension@14f272e7)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:840)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
当我在服务器日志中查找主键值时,我发现:
[#|2013-11-04T18:02:18.846-0700|FINE|glassfish3.1.2|org.eclipse.persistence.session.file:/C:/glassfish3/glassfish/domains/domain1/applications/foo_jar/_bar.sql|_ThreadID=158;_ThreadName=Thread-2;ClassName=null;MethodName=null;|INSERT INTO TIME_DIMENSION (ID, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, JWK_WEEK, JWK_YEAR, MINUTE, MONTH, MONTH_NAME, QUARTER, WEEKDAY, YEAR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [3069178, 2, 6, 306, 15, 44, 2013, 55, 11, November, 2, Saturday, 2013]|#]
--
[#|2013-11-04T18:02:18.865-0700|FINE|glassfish3.1.2|org.eclipse.persistence.session.file:/C:/glassfish3/glassfish/domains/domain1/applications/foo_jar/_bar.sql|_ThreadID=158;_ThreadName=Thread-2;ClassName=null;MethodName=null;|INSERT INTO TIME_DIMENSION (ID, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, JWK_WEEK, JWK_YEAR, MINUTE, MONTH, MONTH_NAME, QUARTER, WEEKDAY, YEAR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [3069178, 3, 7, 307, 5, 44, 2013, 37, 11, November, 2, Sunday, 2013]|#]
--
JPA注解实体如下:
@Entity
@Table(name="TIME_DIMENSION")
public class TimeDimension implements Dimension {
private static final long serialVersionUID = -7496979683190776675L;
@Id
@Column(name="ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="TIME_DIM_SEQ")
@SequenceGenerator(name="TIME_DIM_SEQ",sequenceName="TIME_DIM_SEQ")
private long id;
...
数据库是Oracle 11g。我没有告诉 EclipseLink 底层数据库是 Oracle。我需要吗?我尝试使用不同的选项重新创建索引,是的,增量是 1。有什么想法吗?