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

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

Open
spring-projects-issues opened this issue Mar 14, 2018 · 0 comments
Labels
type: bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Mar 14, 2018

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

@spring-projects-issues spring-projects-issues added the type: bug label Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

1 participant