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

JaversException: MANAGED_CLASS_MAPPING_ERROR JaVers runtime error - given javaClass 'class java.lang.Long' is mapped to java.lang.Long, expected ManagedType #250

Closed
kenti-lan opened this issue Nov 12, 2015 · 17 comments
Labels

Comments

@kenti-lan
Copy link

@kenti-lan kenti-lan commented Nov 12, 2015

I don't not what it mean and how to avoid it?Please tell me,Thanks.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Nov 13, 2015

I dont konw :)
tell me what are you doing, push a failing test which would illustrate and isloate your issue ...

@trav75
Copy link

@trav75 trav75 commented Nov 20, 2015

I am having the exact same problem, except instead of a long type it is a java.lang.String type. I was tying to do an Entity diff compare but kept getting errors about null entity id's from children entities. So I decided to just try to do a ValueObject compare instead. I registered my entities as ValueObjects in the Javers builder. When I do the compare, it blows up with this error:

MANAGED_CLASS_MAPPING_ERROR JaVers runtime error - given javaClass 'class java.lang.String' is mapped to java.lang.String, expected ManagedType
at org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:118)
at org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:102)
at org.javers.core.metamodel.object.GlobalIdFactory.createId(GlobalIdFactory.java:34)
at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:21)
at org.javers.core.graph.EdgeBuilder.asCdo(EdgeBuilder.java:39)
at org.javers.core.graph.EdgeBuilder.buildSingleEdge(EdgeBuilder.java:32)
at org.javers.core.graph.ObjectGraphBuilder.buildSingleEdges(ObjectGraphBuilder.java:81)
at org.javers.core.graph.ObjectGraphBuilder.buildEdges(ObjectGraphBuilder.java:71)
at org.javers.core.graph.ObjectGraphBuilder.buildGraphFromCdo(ObjectGraphBuilder.java:59)
at org.javers.core.graph.ObjectGraphBuilder.buildGraph(ObjectGraphBuilder.java:48)
at org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39)
at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:99)
at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:59)
at org.javers.core.JaversCore.compare(JaversCore.java:95)

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Nov 21, 2015

Guys , i cant help you if you just throw stack traces at me. If this is a bug in javers i need to reproduce it on my mashine. Your task is to isolate the issue and push it as a failing test.

@rschertz
Copy link

@rschertz rschertz commented Nov 25, 2015

I ran into the same thing with a class generated for an Avro schema. Avro defines "string" fields as java.lang.CharSequence which are instances org.apache.avro.util.Utf8 for performance.

For example, given Avro schema AvroString.avsc:

{
"type" : "record",
"name" : "AvroString",
"namespace" : "org.javers.issues.issue250",
"fields" : [
{ "name" : "changedBy", "type" : ["null", "string"], "default" : null, "doc" : "The actual user who made the change." }
]
}

The property in the generated class is:

/** The actual user who made the change. */
@deprecated public java.lang.CharSequence changedBy;

Here's a simple unit test that produces the error:

@Test
public void shouldCompareTwoCharSequences() {
    //given
    Javers javers = JaversBuilder.javers().build();

    CharSequence charSequence1 = "charSequenceOne";
    CharSequence charSequence2 = "charSequenceTwo";

    //when
    Diff diff = javers.compare(charSequence1, charSequence1);
}

But I realize that this exception occurs the same if using a String instead of CharSequence in the test. I'm refactoring tests to compare an object with String property values to an object with Utf8 property values.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Nov 25, 2015

javers.compare() accepts only Entities and ValueObjects (not simple Values like String),
maybe Exception is a bit misleading ...
does it answer your question?

@rschertz
Copy link

@rschertz rschertz commented Nov 26, 2015

That answers why my test is not valid. A not supported message for simple Values like String would be nice.

I reproduced the problem observed when using a generated Avro record class with CharSequence properties that have a String value for the org.apache.avro.Utf8 string property. The test case below exhibits the same exception given two ValueObjects.

private class AvroAddress {
    private final CharSequence city;
    private final CharSequence street;

    public AvroAddress(CharSequence city, CharSequence street) {
        this.city = city;
        this.street = street;
    }

    public CharSequence getCity() { return city; }
    public CharSequence getStreet() { return street; }
}

@Test
public void shouldCompareTwoObjectsWithCharSequencePropertiesOfString() {
    //given
    Javers javers = JaversBuilder.javers().build();

    AvroAddress oldVersion = new AvroAddress("New York", "First Avenue");
    AvroAddress currentVersion = new AvroAddress("New York", "Second Avenue");

    //when
    Diff diff = javers.compare(oldVersion, currentVersion);

    //then
    //there should be one change of type {@link ValueChange}
    ValueChange change = diff.getChangesByType(ValueChange.class).get(0);

    assertThat(diff.getChanges()).hasSize(1);
    //assertThat(change.getAffectedGlobalId().value()).isEqualTo("yadda/");
    assertThat(change.getProperty().getName()).isEqualTo("street");
    assertThat(change.getLeft()).isEqualTo(oldVersion.getStreet());
    assertThat(change.getRight()).isEqualTo(currentVersion.getStreet());

    System.out.println(diff);
}
@bartoszwalacik bartoszwalacik added the bug label Nov 26, 2015
@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Nov 26, 2015

ok, got it, fortunately, it's quite easy to fix

bartoszwalacik added a commit that referenced this issue Nov 26, 2015
bartoszwalacik added a commit that referenced this issue Nov 26, 2015
bartoszwalacik added a commit that referenced this issue Nov 26, 2015
@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Nov 27, 2015

fixed in release 1.3.22

@rschertz
Copy link

@rschertz rschertz commented Dec 3, 2015

Thanks, confirmed changes in 1.3.22.

@Sarvesh-D
Copy link

@Sarvesh-D Sarvesh-D commented May 17, 2016

@bartoszwalacik
Hi,
Still getting this issue on version (1.6.4) :

Caused by: org.javers.common.exception.JaversException: MANAGED_CLASS_MAPPING_ERROR given javaClass 'class java.lang.String' is mapped to PrimitiveType, expected ManagedType at org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:159) ~[javers-core-1.6.4.jar:?] at org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:142) ~[javers-core-1.6.4.jar:?] at org.javers.core.metamodel.object.GlobalIdFactory.createId(GlobalIdFactory.java:44) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:24) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:9) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.EdgeBuilder.asCdo(EdgeBuilder.java:39) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.EdgeBuilder.buildSingleEdge(EdgeBuilder.java:32) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.ObjectGraphBuilder.buildSingleEdges(ObjectGraphBuilder.java:81) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.ObjectGraphBuilder.buildEdges(ObjectGraphBuilder.java:71) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.ObjectGraphBuilder.buildGraphFromCdo(ObjectGraphBuilder.java:59) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.ObjectGraphBuilder.buildGraph(ObjectGraphBuilder.java:48) ~[javers-core-1.6.4.jar:?] at org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39) ~[javers-core-1.6.4.jar:?] at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:109) ~[javers-core-1.6.4.jar:?] at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:64) ~[javers-core-1.6.4.jar:?] at org.javers.core.JaversCore.compare(JaversCore.java:103) ~[javers-core-1.6.4.jar:?]

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 17, 2016

hi @Sarvesh-D
that's only a stack trace, and doesn't help me much, could you provide a failing test case for your issue?

@Sarvesh-D
Copy link

@Sarvesh-D Sarvesh-D commented May 19, 2016

Hi @bartoszwalacik
Somehow i am not able to reproduce it using a test case. However after doing some debugging, i found that org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(Class, Class<T>) method is getting input javaClass as java.lang.String (Though i am giving two complex objects to the compare method which btw are registered as ValueObjects).
I even tried to register java.lang.String as ValueObject, then as ValueType but somewhere it gets overridden as PrimitiveType. Can you provide a workaround to this issue. Thanks!

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 19, 2016

Ok but what is the issue? For now we dont know if it is a javers bug or some problem in your code.
If you see this in your debugger why you cant write a test case with a repro?

@rushikesh-damkondwar
Copy link

@rushikesh-damkondwar rushikesh-damkondwar commented Dec 26, 2016

Hi @bartoszwalacik
Facing same issue.
Using: compile 'org.javers:javers-core:2.8.1'

@Indexed(index = "Company")
public class Company implements Serializable,Cloneable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="pkcompany_id")
	private long id;

	@Field
	@Column(name="address1",length=300)
	private String address1;

	@Field
	@Column(name="address2",length=300)
	private String address2;

	@Field
	@Column(name="city",length=255)
	private String city;

	@Field
	@Column(name="company_name",length=1000)
	private String companyName;

	@Field
	@Column(name="email",length=255)
	private String email;
....
}
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(oldCompany, company);
@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Dec 28, 2016

and what about this Company? If you think you found a bug, please push a failing test case

@joshtheman
Copy link

@joshtheman joshtheman commented Jan 21, 2017

hi,

could u pls tell me what could be wrong:
II try to do a simple javers.diff on 2 instances of a class
Diff diffFoundVsNew = javers.compare(foundEquity, modifiedEquity);
where get the following error:
exception: MANAGED_CLASS_MAPPING_ERROR: given javaClass 'class java.lang.String' is mapped to ValueType, expected ManagedType

here is the prettyprint of the class Entity:

javersType = EntityType{
baseType: class xxx.security.Equity
typeName: Equity
managedProperties:
Field String figi; //declared in Security
Field String description; //declared in Security
Field String ticker; //declared in Security
Field Long version; //declared in VersionedEntity
Field String id; //declared in IdentifiedEntity
idProperty: id
}

thanks for your help

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Jan 21, 2017

guys, I wont help unless you follow the bug report rules. The rules are simple and they are meant to save my time.

You can find the rules in CONTRIBUTING.md https://github.com/javers/javers/blob/master/CONTRIBUTING.md

Bug Reports have to contain:

  1. Clear description of your expectations versus reality
  2. Runnable test case which isolates the bug and allows us to easily reproduce it on our laptops. You can push this test case to your fork of this repository.
@javers javers deleted a comment Jun 16, 2019
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
7 participants
You can’t perform that action at this time.