我在 Spring 3 中使用 Hibernate 4.1.0.Final
我在实体类中有以下内容
@Id
@Column(name = "PROJECT_NO")
@GeneratedValue(strategy=GenerationType.TABLE)
private String projectNumber;
是否可以使用数据库触发器来填充表的主键?或者我必须为此使用 CustomGenerator?
当我尝试上述方法时,出现以下异常
org.hibernate.id.IdentifierGenerationException: Unknown integral data type
for ids : java.lang.String
数据库触发器没有任何序列,它正在使用
SELECT NVL (MAX (project_no), 0) + 1 FROM projects
编辑 1
@GeneratedValue(generator="trig")
@GenericGenerator(name="trig", strategy="select",
parameters=@Parameter(name="key", value="projectNo"))
以上抛出以下异常
Hibernate: select PROJECT_NO from PROJECTS where PROJECT_NO =?
java.lang.NullPointerException
exception in save null
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:645)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:4268)
at org.hibernate.id.SelectGenerator$SelectGeneratorDelegate.bindParameters(SelectGenerator.java:138)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:84)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2764)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3275)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)