简体   繁体   English

org.hibernate.PropertyValueException

[英]org.hibernate.PropertyValueException

i have these Pojos:我有这些 Pojos:

public class ParticipantPojo implements Serializable
.....
@OneToMany(mappedBy = "participant", cascade = CascadeType.ALL)
private Set<ParticipantIdentificationNumberPojo> identificationNumbers;

and

public class ParticipantIdentificationNumberPojo implements Serializable
 ......
@ManyToOne
@JoinColumn(name = "PARTICIPANT", nullable = false)
private ParticipantPojo participant;

When i want to create a new participant with当我想创建一个新参与者时

 ParticipantPojo pojo= new ParticipantPojo ();
 ...
 Set<ParticipantIdentificationNumberPojo> identSet = new HashSet<ParticipantIdentificationNumberPojo>();
 ParticipantIdentificationNumberPojo identInfo= new ParticipantIdentificationNumberPojo();
 identInfo.setType("xyz");
 identInfo.setNumber(12345);
 identSet.add(identInfo);
 pojo.setIdentificationNumbers(identSet);

and save it并保存

 session.save(pojo);

i get the following error:我收到以下错误:

org.hibernate.PropertyValueException: not-null property references a null or transient value: de.seeburger.marktpartnerdaten.database.pojo.ParticipantIdentificationNumberPojo.participant

In a blog i found the solution to set nullable=true at在博客中,我找到了设置 nullable=true 的解决方案

@JoinColumn(name = "PARTICIPANT", nullable = false)

but that is not what i want (participant should not be null.)...setting nullable=true create another exception但这不是我想要的(参与者不应该是 null。)...设置 nullable=true 创建另一个异常

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: de.seeburger.marktpartnerdaten.database.pojo.ParticipantPojo

I think the problem is, that Hibernate does not save the participant and take the ID to save participantIdentificationNumber...but i found no solution for my exception:-(我认为问题是,Hibernate 没有保存参与者并使用 ID 来保存参与者标识号......但我发现我的异常没有解决方案:-(

You have created a bi-directional relationship with ParticipantPojo acting as the defining side (with the mappedBy property in the @OneToMany annotation).您已经创建了一个双向关系, ParticipantPojo作为定义方(使用@OneToMany注释中的mappedBy属性)。 The ParticipantIdentificationNumberPojo is the owning side of the relationship, and you must register the instance of the defining side on the owning side. ParticipantIdentificationNumberPojo是关系的拥有方,您必须在拥有方注册定义方的实例。

So, you will have to register the ParticipantPojo instance as follows:因此,您必须按如下方式注册ParticipantPojo实例:

ParticipantPojo pojo= new ParticipantPojo ();
...
Set<ParticipantIdentificationNumberPojo> identSet = new HashSet<ParticipantIdentificationNumberPojo>();
ParticipantIdentificationNumberPojo identInfo= new ParticipantIdentificationNumberPojo();
identInfo.setType("xyz");
identInfo.setNumber(12345);
identInfo.setParticipantPojo(pojo); // <-- Registering the instance on the owning side.
identSet.add(identInfo);
pojo.setIdentificationNumbers(identSet);

Ideally you must register the relationship in both directions even though you have declared a bi-directional relationship.理想情况下,即使您已声明双向关系,您也必须在两个方向上注册关系。 Hibernate will however make things easy if you set the value on the owning side, as that is the side that contains the foreign key;但是,如果您在拥有方设置值,Hibernate 将使事情变得容易,因为那是包含外键的一方; once you think about this, you'll realize the reason for the second error message that you are getting - foreign keys cannot be null.一旦您考虑到这一点,您就会意识到您收到第二条错误消息的原因 - 外键不能是 null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.propertyvalueexception not-null属性引用null - org.hibernate.propertyvalueexception not-null property references a null Hibernate:使用带有连接表的双向多对一映射持久化实体 - org.hibernate.PropertyValueException - Hibernate: persist entity with bidirectional many-to-one mapping with join table - org.hibernate.PropertyValueException Hibernate异常org.hibernate.PropertyValueException:not-null属性引用了null或瞬态值 - Hibernate exception org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException:非空属性在使用 Spring 引导时引用 null 或瞬态值 - org.hibernate.PropertyValueException: not-null property references a null or transient value while using Spring Boot org.hibernate.PropertyValueException:not-null属性引用一个null或瞬态值:mdl.Complaint.jobDone - org.hibernate.PropertyValueException: not-null property references a null or transient value: mdl.Complaint.jobDone 线程“ main” org.hibernate.PropertyValueException中的异常:not-null属性引用了null或瞬态值 - Exception in thread “main” org.hibernate.PropertyValueException: not-null property references a null or transient value 与问题相关的hibetnate获取“ org.hibernate.PropertyValueException”非null属性引用null - Issue related hibetnate getting “org.hibernate.PropertyValueException” not-null property references a null 尝试发布时出错:org.hibernate.PropertyValueException:非空属性引用 null 或瞬态值 - Getting error while trying to post: org.hibernate.PropertyValueException: not-null property references a null or transient value org.hibernate.PropertyValueException:not-null属性引用一个空值或瞬态值:com.rasvek.cms.entity.State.country - org.hibernate.PropertyValueException: not-null property references a null or transient value : com.rasvek.cms.entity.State.country 当我提交表单时,我收到此错误 org.hibernate.PropertyValueException: not-null property references a null 或瞬态值 - When I submit the form I get this error org.hibernate.PropertyValueException: not-null property references a null or transient value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM