我整个下午都在看这个,我很难过。为什么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.任何想法?
答案 0 :(得分:1)
您可以尝试添加allocationSize=1
吗?如:
@SequenceGenerator(name="TIME_DIM_SEQ",sequenceName="TIME_DIM_SEQ",allocationSize=1)
这里写的是你必须提供allocationSize
等于序列的INCREMENT BY
: