infobip / infobip-spring-data-querydsl

Infobip Spring Data Querydsl provides new functionality that enables the user to leverage the full power of Querydsl API on top of Spring Data repository infrastructure.
Apache License 2.0
281 stars 56 forks source link

@Transient field breaks application context #54

Closed kirill-kravchenko closed 2 years ago

kirill-kravchenko commented 2 years ago

Hi! I'm using infobip-spring-data-jdbc-querydsl-boot-starter 6.2.1 version with querydsl 5.0.0 And when I use @Transient like in the following block:

@Table("entity")
@Data
@Builder
@RequiredArgsConstructor
public class Entity {

    @Id
    private final Long id;

    @Transient
    private final boolean isNew;
}

I get exception:

Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: java.lang.NullPointerException
    at com.querydsl.core.types.ConstructorExpression.getParameterTypes(ConstructorExpression.java:59)
    at com.querydsl.core.types.ConstructorExpression.<init>(ConstructorExpression.java:74)
    at com.querydsl.core.types.Projections.constructor(Projections.java:121)
    at com.infobip.spring.data.common.QuerydslExpressionFactory.getConstructorExpression(QuerydslExpressionFactory.java:54)
    at com.infobip.spring.data.jdbc.QuerydslJdbcRepositoryFactory.getRepositoryFragments(QuerydslJdbcRepositoryFactory.java:73)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryComposition(RepositoryFactorySupport.java:371)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:276)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:323)
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:230)
    at org.springframework.data.util.Lazy.get(Lazy.java:114)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:329)
    at org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean.afterPropertiesSet(JdbcRepositoryFactoryBean.java:201)
    at com.infobip.spring.data.jdbc.QuerydslJdbcRepositoryFactoryBean.afterPropertiesSet(QuerydslJdbcRepositoryFactoryBean.java:161)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
    ... 162 more

Looks like https://github.com/infobip/infobip-spring-data-querydsl/issues/18 problem.

lpandzic commented 2 years ago

Hello, if I remember correctly, a constructor without @Transient field is required and it should be marked with @PersistenceConstructor. For details check out related test classes.

lpandzic commented 2 years ago

I'm closing this one, please read the above reply and if it doesn't work or if you have any more question feel free to reopen.