Skip to content

NullPointerException when using composite id with 'exists' repository method [DATAJPA-1290] #1616

Open
@spring-projects-issues

Description

@spring-projects-issues

cda opened DATAJPA-1290 and commented

Given the following classes:

@Embeddable
public class PriceHistoryId implements Serializable {
    private Product product;
    private OffsetDateTime date;
}
@Entity
@IdClass(PriceHistoryId.class)
public class PriceHistory {
    @NotNull @Embedded
    private Price price;

    @Id @NotNull
    protected OffsetDateTime date;

    @Id
    @ManyToOne
    @NotNull
    @JoinColumn
    private Product product;
}
@Repository
public interface PriceHistoryRepository extends JpaRepository<PriceHistory, PriceHistoryId> {
    boolean existsByProduct( Product product );
}

throws NullPointerException when building repository bean:

Caused by: java.lang.IllegalArgumentException: Failed to create query method public abstract boolean PriceHistoryRepository.existsByProduct(Product)! null
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:76)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:101)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:207)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
	... 83 more
Caused by: java.lang.NullPointerException
	at org.hibernate.jpa.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:123)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:187)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:143)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:52)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:133)
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:72)
	... 93 more

Issue is in JpaQueryCreator.java(line 187):

selections.add(root.get((SingularAttribute) id).alias(id.getName()));

where id variable is null.

This issue is replicable only with an exists query.
Issue is replicable also with spring-data-jpa version 1.11.10.RELEASE.


No further details from DATAJPA-1290

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions