0
我正在使用JPA2.0和休眠4休眠生成使用触发器主键
为了生成表中的主键,我使用表触发器。如果我是 ,使用Long作为主键的数据类型,则触发器正常工作。但是,如果我使用字符串作为主键 数据类型,那么我收到以下错误。
org.springframework.orm.hibernate3.HibernateSystemException: Unknown integral
data type for ids : java.lang.String; nested exception is
org.hibernate.id.IdentifierGenerationException: Unknown integral
data type for ids : java.lang.String at
org.springframework.orm.hibernate3.SessionFactoryUtils.
convertHibernateAccessException(SessionFactoryUtils.java:690)
那么是不是允许使用字符串为主键生成使用触发器的值?
我的代码片段使用触发
private String deptNo;
@Id
@GenericGenerator(name = "trig", strategy = "increment")
@GeneratedValue(generator = "trig")
@Column(name = "DEPT_NO")
public String getDeptNo() {
return deptNo;
}
public void setDeptNo(String deptNo) {
this.deptNo = deptNo;
}
dursun通过使用String作为适配器类,究竟是什么意思?你的意思是创建自定义类来生成密钥? – user75ponic 2013-05-11 09:59:22
不,我的意思是为当前类创建另一个对象,例如,如果您的当前类是Employee,则可以创建AdaptorEmployee,将Employees的deptNo属性转换为一个字符串。 – dursun 2013-05-11 10:13:50
所以当我写数据库时,我应该调用AdaptorEmployee类? – user75ponic 2013-05-11 10:35:16