Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempted to assign id from null one-to-one property [DATAJPA-1304] #1628

Closed
spring-projects-issues opened this issue Mar 27, 2018 · 10 comments
Closed
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Mar 27, 2018

Chursin Evgeny opened DATAJPA-1304 and commented

catch very unexpected exception while updgrading hibernate version 5.2.12 -> 5.2.15

org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [models.Secunda.parent]

in scenario when update object with non null OneToOne property.

i can`t undestend whos to blame.

i create test project to easy reproduce this case - https://github.com/evg345/spring-data-hibernate-bug

@Entity
public class Prima implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    //@PrimaryKeyJoinColumn
    @OneToOne(mappedBy = "parent", optional = true , cascade = CascadeType.ALL)
    Secunda optionalData;
}

@Entity
public class Secunda implements Serializable {

    @Id
    @Column(name = "id", nullable = false)
    Long id;

    @MapsId
    @OneToOne(optional = false)
    @JoinColumn(name = "id", nullable = false)
    Prima parent;
}

class Test {
   Long primaId;
   void beforTest() {
        Prima prim = new Prima();
        prim.setOptionalData(null); // <-- null
        prim = repoPrima.save(prim);
       this.primaId = prim.getId();
   }

   void test() {
        // we emulate object recieved from json
        Prima prim = new Prima();
        prim.setId(this.primaId);
        {
            Secunda sec = new Secunda();
            sec.setParent(prim); // <-- not null ! ! !
            prim.setOptionalData(sec);
        }

        Prima savedPrima = repoPrima.save(prim); // <-- exception here
  }
}

Once again, this code works with Hibernate 5.2.12 , 5.2.13
and fail when change Hibernate version in pom file to 5.2.14 , 5.2.16

I expect that is bug somewhere inside Spring-Data , but it can hides in Hibernate :(


Affects: 2.0.5 (Kay SR5)

Reference URL: https://github.com/evg345/spring-data-hibernate-bug/blob/master/src/test/java/bugreport/OneToOnePropertyTest.java

Issue Links:

  • DATAJPA-1306 Cannot update bidirectional one-to-one if non-mappedBy entity was null
    ("is duplicated by")

0 votes, 6 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 27, 2018

Oliver Drotbohm commented

I don't see anything that's Spring Data specific here. The second save(…) call is ending up as EntityManager.merge(…) so you should be able to see this error with plain Hibernate, too. Did you already report that to Hibernate?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 27, 2018

Chursin Evgeny commented

yes, i report it to hibernate too. https://hibernate.atlassian.net/browse/HHH-12436

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 27, 2018

Oliver Drotbohm commented

Thanks, I'm gonna link the issue for reference. The Hibernate team usually reacts much quicker if you can provide a test case that doesn't include anything Spring as they can then rule out that the issue has something to do with a different framework. However, let's how they respond

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 27, 2018

Chursin Evgeny commented

i have reproduce error on pure hibernate. Spring-Data is innocent.

also i provide a test case as pull request ... but im not sure that i done everthing correct. its my first time :D

greate thanx for your replay ! :)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

Jens Schauder commented

This is a Hibernate issue

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 28, 2018

Daniel Silveira commented

This affects our adoption of spring-boot 2.0, as it uses hibernate 5.2.14+

Is there a workaround on this? 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 29, 2018

Oliver Drotbohm commented

I don't think there's anything in Spring Boot that particularly requires 5.2.14. Have you tried setting Boots hibernate.version to 5.2.13 explicitly? I guess it should work just fine on that version

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 29, 2018

Daniel Silveira commented

I saw here (https://mvnrepository.com/artifact/org.springframework.boot/spring-boot/2.0.0.RELEASE) that spring-boot has dependency on hibernate-core 5.2.14.Final

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 29, 2018

Daniel Silveira commented

I just tried setting

<properties>
   <hibernate.version>5.2.13</hibernate.version>
</properties>

But build shows 

Error:(7, 25) java: package javax.persistence does not exist

Later i'll look more into it.

Thanks anyway

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 13, 2019

Vanitha R commented

Daniel Silveira how did you workaround this?. When i set the hibernate version to 5.2.13 I'm also facing the same issue. I don't want to downgrade to a lower version of spring boot for this, since its a greenfield project, wanted to start with the latest stable version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.