问题描述
在我的Hibernate应用程序中,我使用了创建ValueObject类的方法
In my Hibernate Application i'm using create a ValueObject class
@Entity
@Table(name="user")
public class UserVO{
@Id
@Column(name="S_ID")
private String s_id;
@Column(name="FIRSTNAME")
private String firstName;
@Column(name="LASTNAME")
private String lastName;
}
在我的Service类中,我写的是这样的
and in my Service class i'm writing like this
public void createOrUpdateUser(UserVO userVO) {
userDAO.createOrUpdateUser(userVO);
}
在我的DAO类中,我写的是这样的
and in my DAO class i'm writing like this
private EntityManager entityManager;
public void createOrUpdateUser(UserVO userVO) throws DataAccessException {
entityManager.persist(userVO);
}
现在我打电话给createOrUpdateUser(userVO),但它给出错误
now i'm calling createOrUpdateUser(userVO) but it give error
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
实际上,我的数据库为<$ c创建了一个 trigger
$ c> user 表为 s_id
列生成唯一标识是它们触发时的任何问题。请给我建议。
Actually my data base i have created one trigger
for user
table to generate unique id for s_id
column is their any problem for trigger..please suggest me..
推荐答案
ID列不能为null,无论你在数据库驱动程序中做什么,只会在插入或任何其他操作之前/之后触发,但根据
ID column must not be null, whatever you do in database driver, will only be trigger before/after insert or any other operation, But according to error it is giving error before any error.
将某些内容设置为ID值或尝试一些操作
@GeneratedValue(strategy = GenerationType.IDENTITY )
Set something to ID values or try something @GeneratedValue(strategy = GenerationType.IDENTITY)
这篇关于如何将Trigger生成的值赋予Hibernate ValueObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!