question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem reading Shadows with EmbeddedId

See original GitHub issue

I’m using javers 5.7.2 and have a problem reading nested collection of AgreementMember objects in Agreement. It’s a regilar OneToMany relation except AgreementMember has a composite primary key. Here are the classes:

Agreement.java:

@TypeName("Agreement")
public class Agreement
{
    @Id
    private UUID agreementId;

    private UUID locationId;

    @OneToMany(mappedBy = "agreement", cascade = CascadeType.ALL, orphanRemoval = true)
    @ShallowReference
    private List<AgreementMember> agreementMembers;

    //other fields ...
}

AgreementMember.java: with AgreementMemberId as primary key:

@TypeName("AgreementMember")
public class AgreementMember
{
    public AgreementMemberId getId()
    {
        return agreementMemberId;
    }


    @Embeddable
    @TypeName("AgreementMemberId")
    public static class AgreementMemberId implements Serializable
    {
        private UUID agreementId;
        private UUID memberId;
    }

    @EmbeddedId
    private AgreementMemberId agreementMemberId;

    //other fields ...
}

Here is a snapshot

[
   Snapshot   {
      commit:1.0,
      id:Agreement/a3ffda86-ba8b-4640-bd03-4ad945aa2546,
      version:1,
      (agreementId:a3ffda86-ba8b-4640-bd03-4ad945aa2546,
      agreementMembers:[
         AgreementMember/a3ffda86-ba8b-4640-bd03-4ad945aa2546,
         50527728-0f56-4403-8651-7f9eff2dda93
      ],
      locationId:1b1e5b47-ba10-4bb7-9f04-6b81d1c66422)
   }
]

And here is an exception when I’m trying to read shadows:

org.javers.shadow.ShadowGraphBuilder#assembleShallowReferenceShadow java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at path $.agreementMemberId

And here is my test:

@Test
void testAgreement()
{
    //given
    Javers javers = JaversBuilder.javers()
            .withListCompareAlgorithm(ListCompareAlgorithm.SIMPLE)
            .build()

    Agreement agreement = new Agreement()
    agreement.agreementId = UUID.randomUUID()
    agreement.locationId = UUID.randomUUID()

    AgreementMember.AgreementMemberId agreementMemberId = new AgreementMember.AgreementMemberId()
    agreementMemberId.agreementId = agreement.agreementId
    agreementMemberId.memberId = UUID.randomUUID()

    AgreementMember agreementMember = new AgreementMember()
    agreementMember.agreementMemberId = agreementMemberId

    List<AgreementMember> agreementMemberList = new ArrayList<>()
    agreementMemberList.add(agreementMember)
    agreement.agreementMembers = agreementMemberList

    javers.commit("Agreement", agreement)

    JqlQuery query = QueryBuilder.byInstanceId(agreement.agreementId, Agreement.class).build()
    List<Shadow<Agreement>> shadows = javers.findShadows(query)
    println shadows
}

Any help is greatly appreciated. This might me misconfiguration or something, please advice.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bartoszwalacikcommented, Oct 23, 2019

bug report confirmed

1reaction
bartoszwalacikcommented, Sep 25, 2019

ok, now I can look on this test case, stay tuned

Read more comments on GitHub >

github_iconTop Results From Across the Web

There should be one non-read-only mapping defined for the ...
embeddedId.clubId , whenever the entity is fetched/refreshed. Whatever mapping you put on Team.embeddedId.clubId will be ignored. The error ...
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Hibernate not only takes care of the mapping from Java classes to database ... The ability to read/write this data from/to the database...
Read more >
Release notes — JaVers Documentation
1014 Fixed issue with Shadows with boolean properties. ... The exception was thrown on attempt to read Shadows with a ShallowReference with EmbeddedId...
Read more >
Spring Data JDBC - Reference Documentation
Attributes annotated with @ReadOnlyProperty will not be written to the database by Spring Data JDBC, but they will be read when an entity...
Read more >
Activiti User Guide
Every self-respecting developer should have read How to ask questions the smart ... As an embeddable process engine, Activiti is not concerned with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found