当我尝试运行本机查询时,当我尝试在 spring jpa 中运行时,出现以下错误native query。我已将方言添加到自定义方言中,扩展为
spring.jpa.database-platform=com.config.HibernateCustomDialect
Caused by: java.lang.NullPointerException: null
at com.vladmihalcea.hibernate.type.array.internal.AbstractArrayTypeDescriptor.setParameterValues(AbstractArrayTypeDescriptor.java:34) ~[hibernate-types-52-2.6.1.jar:na]
at com.vladmihalcea.hibernate.type.array.StringArrayType.setParameterValues(StringArrayType.java:50) ~[hibernate-types-52-2.6.1.jar:na]
at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:149) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.type.TypeFactory.type(TypeFactory.java:135) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
下面是我的实体
@Entity
@Getter
@Setter
@NoArgsConstructor
@TypeDef(
name = "string-array",
typeClass = StringArrayType.class
)
public class Session {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long sessionId;
@Type(type = "string-array")
@Column(columnDefinition = "text[]", name = "tags")
private String[] tags = null;
private long oId;
// More Fields
}
自定义方言
public class HibernateCustomDialect extends org.hibernate.dialect.PostgreSQL94Dialect {
private static final Logger log = LoggerFactory.getLogger(HibernateCustomDialect.class);
public HibernateCustomDialect() {
super();
log.info("Registering Custom Hibernate Dialect - {}",HibernateCustomDialect.class.getName());
this.registerHibernateType(Types.ARRAY, StringArrayType.class.getName());
}
}
Jpa 存储库
@Repository
public interface SessionRepository extends JpaRepository<Session, Long> {
String sessionSummaryViewQuery ="SELECT session.session_id, session.tags FROM public.session WHERE session.oid=?1"
@Query(value =sessionSummaryViewQuery,nativeQuery = true)
List<SessionSummaryView> findByOpportunityId(long opportunityId);//, Pageable pageable);
}
缥缈止盈
相关分类