babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
824 stars 80 forks source link

use @idview field in spec dto cause NullPointerException #447

Closed qifan777 closed 8 months ago

qifan777 commented 8 months ago

use @idview field in spec dto cause NullPointerException

Exception

java.lang.NullPointerException: Cannot invoke "org.babyfish.jimmer.meta.ImmutableType.getJavaClass()" because "type" is null
    at org.babyfish.jimmer.sql.ast.impl.table.TableProxies.createConstructor(TableProxies.java:115)
    at org.babyfish.jimmer.sql.ast.impl.table.TableProxies.createFluentConstructor(TableProxies.java:67)
    at org.babyfish.jimmer.impl.util.TypeCache.get(TypeCache.java:80)
    at org.babyfish.jimmer.sql.ast.impl.table.TableProxies.fluent(TableProxies.java:52)
    at org.babyfish.jimmer.sql.ast.table.spi.AbstractTypedTable.join(AbstractTypedTable.java:275)
    at org.babyfish.jimmer.sql.ast.table.spi.AbstractTypedTable.getAssociatedId(AbstractTypedTable.java:196)
    at org.babyfish.jimmer.sql.ast.table.spi.AbstractTypedTable.get(AbstractTypedTable.java:166)
    at org.babyfish.jimmer.sql.ast.query.specification.PredicateApplier.eq(PredicateApplier.java:63)
    at io.qifan.mall.server.coupon.user.entity.dto.CouponUserSpec.applyTo(CouponUserSpec.java:159)
    at org.babyfish.jimmer.sql.ast.impl.query.MutableRootQueryImpl.where(MutableRootQueryImpl.java:229)
    at io.qifan.mall.server.coupon.user.repository.CouponUserRepository.findPage(CouponUserRepository.java:31)
    at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:76)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:249)
    at jdk.proxy2/jdk.proxy2.$Proxy132.findPage(Unknown Source)
    at io.qifan.mall.server.coupon.user.service.CouponUserService.query(CouponUserService.java:43)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)

Code

Entity

@Entity
@GenEntity
@Table(name = "coupon_user_rel")
public interface CouponUser extends BaseEntity {

// ...

  @GenField(value = "拥有者", order = 2)
  @ManyToOne
  User user();

  @IdView
  String userId();
// ...
}

Spec Dto

specification CouponUserSpec {
    #allScalars
    userId
}

QueryMethod

public interface CouponUserRepository extends JRepository<CouponUser, String> {

  CouponUserTable couponUserTable = CouponUserTable.$;
  CouponUserFetcher COMPLEX_FETCHER = CouponUserFetcher.$.allScalarFields();
  default Page<CouponUser> findPage(QueryRequest<CouponUserSpec> queryRequest,
      Fetcher<CouponUser> fetcher) {
    CouponUserSpec query = queryRequest.getQuery();
    Pageable pageable = queryRequest.toPageable();
    return sql().createQuery(couponUserTable)
        .where(query) 
        .orderBy(SpringOrders.toOrders(couponUserTable, pageable.getSort()))
        .select(couponUserTable.fetch(fetcher))
        .fetchPage(queryRequest.getPageNum() - 1, queryRequest.getPageSize(),
            SpringPageFactory.getInstance());
  }
}
babyfish-ct commented 8 months ago

Try 0.8.102