线程"main"中的异常org.hibernate.TransientObjectException [英] Exception in thread "main" org.hibernate.TransientObjectException

查看:56
本文介绍了线程"main"中的异常org.hibernate.TransientObjectException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个班级 Employe(id,Nom,solde ...) Conge(id,duree,...)
我使用Annotation,并在测试类中放入以下代码来更新de employee的"solde":

I have 2 classes Employe(id,Nom,solde...) and Conge(id,duree,...)
I use Annotation and in my test class I put this code to update the "solde" of de employee:

Employe p=new Employe();
        p.getSolde();
        p.setSolde(sol.sold(17,2));
        da.updateEmploye(p);

但是我有一个错误:

线程"main"中的异常org.hibernate.TransientObjectException:给定的对象具有空标识符:metier.Employe

Exception in thread "main" org.hibernate.TransientObjectException: The given object has a null identifier: metier.Employe

推荐答案

通常,当您尝试保存对象而不保存其依赖项时,会出现 org.hibernate.TransientObjectException .

Usually a org.hibernate.TransientObjectException is when you try to save an object without saving his dependencies.

拥有包含实体 B 的实体 A 时,应在之前创建实体 B 您可以创建实体 A .

When you have an Entity A which contain an Entity B, you should create the Entity B before you can create the Entity A.

B b = new B();
session.save(b);
A a = new A();
a.setB(b);
session.save(a);

或者您也可以使用级联来指示保存 A

Or you can also use Cascade to indicate to hibernate to save B when saving A

这篇关于线程"main"中的异常org.hibernate.TransientObjectException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆