org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity2

Hibernate JIRA | Amar Laddha | 12 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    {code:java} @Entity // Other annotations public class RelatedEntities { // ... other mappings @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity1__id", updatable = true, columnDefinition = "int(10)" , nullable = false ) private Entity1 entity1; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity2__id", updatable = true, columnDefinition = "int(10)" , nullable = true ) private Entity2 entity2; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity3__id", updatable = true, columnDefinition = "int(10)" , nullable = true ) private Entity3 entity3; } @Entity // Other annotations public class Entity1 { // ... other mappings @OneToMany( mappedBy = "entity1", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } @Entity // Other annotations public class Entity2 { // ... other mappings @OneToMany( mappedBy = "entity2", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } @Entity // Other annotations public class Entity3 { // ... other mappings @OneToMany( mappedBy = "entity3", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } {code} When trying to persist an object of RelatedEntities with null value for entity2, hibernate throws following exception: {code:java} org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity2 at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:92) at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:115) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:597) at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:232) at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:213) at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:256) at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318) at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113) at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:778) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:751) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:756) {code} Similarly when trying to persist an object of RelatedEntities with null value for entity3, hibernate throws same exception for example.RelatedEntities.entity3: {code:java} org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity3 {code} Above piece of code works perfectly with hibernate version 4.3.8.Final

    Hibernate JIRA | 12 months ago | Amar Laddha
    org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity2
  2. 0

    {code:java} @Entity // Other annotations public class RelatedEntities { // ... other mappings @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity1__id", updatable = true, columnDefinition = "int(10)" , nullable = false ) private Entity1 entity1; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity2__id", updatable = true, columnDefinition = "int(10)" , nullable = true ) private Entity2 entity2; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "entity3__id", updatable = true, columnDefinition = "int(10)" , nullable = true ) private Entity3 entity3; } @Entity // Other annotations public class Entity1 { // ... other mappings @OneToMany( mappedBy = "entity1", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } @Entity // Other annotations public class Entity2 { // ... other mappings @OneToMany( mappedBy = "entity2", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } @Entity // Other annotations public class Entity3 { // ... other mappings @OneToMany( mappedBy = "entity3", fetch = FetchType.LAZY ) @BatchSize( size = 1024 ) private Set<RelatedEntities> relatedEntities = new HashSet<>(); } {code} When trying to persist an object of RelatedEntities with null value for entity2, hibernate throws following exception: {code:java} org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity2 at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:92) at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:115) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:597) at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:232) at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:213) at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:256) at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318) at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113) at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:778) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:751) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:756) {code} Similarly when trying to persist an object of RelatedEntities with null value for entity3, hibernate throws same exception for example.RelatedEntities.entity3: {code:java} org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity3 {code} Above piece of code works perfectly with hibernate version 4.3.8.Final

    Hibernate JIRA | 12 months ago | Amar Laddha
    org.hibernate.PropertyValueException: not-null property references a null or transient value : example.RelatedEntities.entity2
  3. 0

    Unable to save entity in database when field mapping a foreign key is null

    Stack Overflow | 3 years ago | Kleber Mota
    org.hibernate.PropertyValueException: not-null property references a null or transient value : com.spring.loja.model.pagina.persistence.model.Pagina.nome
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    form:select don't save value in the database

    Stack Overflow | 3 years ago | Kleber Mota
    org.hibernate.PropertyValueException: not-null property references a null or transient value : com.spring.loja.model.pagina.persistence.model.Pagina.nome
  6. 0

    Hibernate exception org.hibernate.PropertyValueException: not-null property references a null or transient value

    Stack Overflow | 2 years ago
    org.hibernate.PropertyValueException: not-null property references a null or transient value : com.sample.Answer.question

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.PropertyValueException

      not-null property references a null or transient value : example.RelatedEntities.entity2

      at org.hibernate.engine.internal.Nullability.checkNullability()
    2. Hibernate
      SessionImpl.persist
      1. org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:92)
      2. org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:115)
      3. org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69)
      4. org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:597)
      5. org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:232)
      6. org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:213)
      7. org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:256)
      8. org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
      9. org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
      10. org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
      11. org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
      12. org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
      13. org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
      14. org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
      15. org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:778)
      16. org.hibernate.internal.SessionImpl.persist(SessionImpl.java:751)
      17. org.hibernate.internal.SessionImpl.persist(SessionImpl.java:756)
      17 frames