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.

Entity literal preferred over path in parsing when entity name and attribute names conflict

See original GitHub issue

Description

Hi, I recently discovered Blaze Persistence and so far has been great at solving some issues I was having. I have arrived at a particular issue that I cant seem to find the solution for. I am trying to use nested view for ManyToOne mapping but gets an error, this is not a bug report but more of a request for help.

Entities

Some fields removed for simplicity

Subject

@Audited
@Entity(name = "curriculum_subject")
public class SubjectImpl implements Subject {

    private String uid;

    @JsonDeserialize(as = SchoolImpl.class)
    @JsonFilter(JsonFilterConstants.UID_ONLY)
    private School school;

    @Id
    @Column(name = "id")
    @GenericGenerator(name  = "uid64", strategy = "com.-.data.util.UID64Generator")
    @GeneratedValue(generator = "uid64")
    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @ManyToOne(targetEntity = SchoolImpl.class, optional = false, fetch = FetchType.LAZY)
    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }
}

School

@Audited
@Entity(name = "school")
@NoArgsConstructor
public class SchoolImpl implements School {

    private String uid;

    private String name;

    @Id
    @Column(name = "id")
    @GenericGenerator(name  = "uid64", strategy = "com.-.data.util.UID64Generator")
    @GeneratedValue(generator = "uid64")
    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @Column(name = "school_name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Views

These are the complete views, nothing removed

Subject

@EntityView(SubjectImpl.class)
public interface SubjectView extends DomainView {
    String getName();
    String getShortName();
    SchoolView getSchool();
}

School

@EntityView(SchoolImpl.class)
public interface SchoolView extends DomainView {
    String getName();
}

Domain

public interface DomainView {
    @IdMapping
    String getUid();
}

Stacktrace

Whenever I try to build I get the following error

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createEntityViewManager' defined in class path resource [com/-/main/configuration/BlazePersistenceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.view.EntityViewManager]: Factory method 'createEntityViewManager' threw exception; nested exception is java.lang.IllegalArgumentException: There are error(s) in entity views!
The resolved possible types [javax.persistence.metamodel.EntityType] are not assignable to the given expression type 'com.-.domain.modules.school.entity.impl.SchoolImpl' of the mapping expression declared by the attribute school[com.-.domain.modules.curriculum.view.SubjectView.getSchool]!
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	... 95 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.view.EntityViewManager]: Factory method 'createEntityViewManager' threw exception; nested exception is java.lang.IllegalArgumentException: There are error(s) in entity views!
The resolved possible types [javax.persistence.metamodel.EntityType] are not assignable to the given expression type 'com.-.domain.modules.school.entity.impl.SchoolImpl' of the mapping expression declared by the attribute school[com.-.domain.modules.curriculum.view.SubjectView.getSchool]!
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
	... 108 more
Caused by: java.lang.IllegalArgumentException: There are error(s) in entity views!
The resolved possible types [javax.persistence.metamodel.EntityType] are not assignable to the given expression type 'com.-.domain.modules.school.entity.impl.SchoolImpl' of the mapping expression declared by the attribute school[com.-.domain.modules.curriculum.view.SubjectView.getSchool]!
	at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:275)
	at com.blazebit.persistence.view.impl.EntityViewConfigurationImpl.createEntityViewManager(EntityViewConfigurationImpl.java:206)
	at com.-.main.configuration.BlazePersistenceConfig.createEntityViewManager(BlazePersistenceConfig.java:35)
	at com.-.main.configuration.BlazePersistenceConfig$$EnhancerBySpringCGLIB$$76fc933b.CGLIB$createEntityViewManager$0(<generated>)
	at com.-.main.configuration.BlazePersistenceConfig$$EnhancerBySpringCGLIB$$76fc933b$$FastClassBySpringCGLIB$$39a92948.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at com.-.main.configuration.BlazePersistenceConfig$$EnhancerBySpringCGLIB$$76fc933b.createEntityViewManager(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 109 more

With the above error while building application I can see the following generated classes

SubjectView_

@Generated(value = "com.blazebit.persistence.view.processor.EntityViewAnnotationProcessor")
@StaticMetamodel(SubjectView.class)
public abstract class SubjectView_ {
    public static volatile MethodSingularAttribute<SubjectView, String> name;
    public static volatile SchoolViewRelation<SubjectView, MethodSingularAttribute<SubjectView, SchoolView>> school;
    public static volatile MethodSingularAttribute<SubjectView, String> shortName;
    public static volatile MethodSingularAttribute<SubjectView, String> uid;

    public static final String NAME = "name";
    public static final String SCHOOL = "school";
    public static final String SHORT_NAME = "shortName";
    public static final String UID = "uid";
    public static final String SCHOOLNAME = "school.name";
    public static final String SCHOOLUID = "school.uid";

    public static EntityViewSetting<SubjectView, CriteriaBuilder<SubjectView>> createSettingInit() {
        return EntityViewSetting.create(SubjectView.class, "init");
    }
    public static EntityViewSetting<SubjectView, PaginatedCriteriaBuilder<SubjectView>> createPaginatedSettingInit(int firstResult, int maxResults) {
        return EntityViewSetting.create(SubjectView.class, firstResult, maxResults, "init");
    }
}

SubjectViewImpl

@Generated(value = "com.blazebit.persistence.view.processor.EntityViewAnnotationProcessor")
@StaticImplementation(SubjectView.class)
public class SubjectViewImpl implements SubjectView, EntityViewProxy {

    public static volatile EntityViewManager ENTITY_VIEW_MANAGER;
    public static final SerializableEntityViewManager SERIALIZABLE_ENTITY_VIEW_MANAGER = new SerializableEntityViewManager(SubjectViewImpl.class, ENTITY_VIEW_MANAGER);

    private final String name;
    private final SchoolView school;
    private final String shortName;
    private final String uid;

    public SubjectViewImpl(SubjectViewImpl noop, Map<String, Object> optionalParameters) {
        this.name = null;
        this.school = null;
        this.shortName = null;
        this.uid = null;
    }

    public SubjectViewImpl(        String uid) {
        this.$$_kind = (byte) 1;
        this.name = null;
        this.school = null;
        this.shortName = null;
        this.uid = uid;
    }

    public SubjectViewImpl(
        String uid,
        String name,
        SchoolView school,
        String shortName
    ) {
        super();
        this.name = name;
        this.school = school;
        this.shortName = shortName;
        this.uid = uid;
    }

    public SubjectViewImpl(SubjectViewImpl noop, int offset, Object[] tuple) {
        super();
        this.name = (String) tuple[offset + 1];
        this.school = (SchoolView) tuple[offset + 2];
        this.shortName = (String) tuple[offset + 3];
        this.uid = (String) tuple[offset + 0];
    }

    public SubjectViewImpl(SubjectViewImpl noop, int offset, int[] assignment, Object[] tuple) {
        super();
        this.name = (String) tuple[offset + assignment[1]];
        this.school = (SchoolView) tuple[offset + assignment[2]];
        this.shortName = (String) tuple[offset + assignment[3]];
        this.uid = (String) tuple[offset + assignment[0]];
    }


    @Override
    public String getName() {
        return name;
    }
    @Override
    public SchoolView getSchool() {
        return school;
    }
    @Override
    public String getShortName() {
        return shortName;
    }
    @Override
    public String getUid() {
        return uid;
    }
...

Environment

Version: 1.5.1
JPA-Provider: Hibernate 5.4.15.Final DBMS: Postgres 11
Application Server: Java EE with Spring Data

If I remove getSchool() from the SubjectView the error goes away. Any idea what I am doing wrong or missing. I am still going through the documentations and appreciate any pointers that could help in my troubles. Hopefully the information provided is enough, thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
garfieldcokedcommented, Apr 23, 2021

Confirming that changing to uppercase also removed the error

1reaction
beikovcommented, Apr 23, 2021

So in JPQL/HQL there are two ways to refer to an entity. Through the FQCN and the entity name. The name you specify in @Entity(name = "") is the entity name. This is mostly important for doing type checks e.g. WHERE TYPE(e) = School in polymorphic scenarios. Anyway, usually, people use upper case entity names and if you omit the name, it will use the simple class name as entity name by default i.e. SchoolImpl.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hibernate ORM 5.2.18.Final User Guide - Red Hat on GitHub
Literals ; 15.24. ... Tracking entity names modified during revisions; 21.7. ... Now the "path" to attributes are used in the implicit column...
Read more >
Extensible Markup Language (XML) 1.0 (Fifth Edition) - W3C
The only way to get a #xD character to match this production is to use a character reference in an entity value literal....
Read more >
#ifundefined - Rocket Software Documentation
Test if a constant has not been defined.
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages ... 1020, 15, No, Sub-entity lists (such as column or security ......
Read more >
A Roadmap to XML Parsers in Python - Real Python
Attributes ; Comments; Character data ( CDATA ); Predefined and custom entities. Go ahead, save the XML in a file named smiley.svg ...
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