Spring Hibernate:没有针对JDBC类型的方言映射:-101

时间:2018-10-02 21:23:14

标签: java spring hibernate spring-data-jpa

我正在开发一个Spring Boot应用程序,并试图构建我的存储库,并且Hibernate遇到了问题。

Pom依赖项:(还有更多,只发布我认为相关的内容)

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.6.Final</version>
</dependency>

Application.properties

# Properties for Spring datasources
#
# If multiple datasources are needed, the autoconfiguration will need
# to be excluded (add "(exclude = DataSourceAutoConfiguration.class)" to the
# @SpringBootApplication annotation in TankInventoryApplication).
#
# Then manual datasources will have to configured in a @Configuration annotated config class
#
spring.datasource.url=<url>
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true


# Properties for Hibernate
#
# Use empty string for hbm2ddl.auto to suppress warning message
# hibernate.hbm2ddl.auto=validate - doesn't work
#
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.useSecondLevelCache=false
hibernate.cacheProviderClass=net.sf.ehcache.hibernate.EhCacheProvider
hibernate.cacheRegionFactoryClass=net.sf.ehcache.hibernate.EhCacheRegionFactory
hibernate.hbm2DdlAuto=

存储库:

//@Repository
//public interface PWeightTagsRepository extends JpaRepository<PTags, Integer>{
//
//    @Query(value = "SELECT T FROM PTags T WHERE T.adbLDeliveryStatus = 'N' ORDER BY T.adbSequence ASC")
//    List<PTags> getNewMessages();
//}

@Repository
public class PWeightTagsRepository{
    @Autowired
    protected EntityManager em;

    public List<PTags> getNewMessages(Integer limit){
        javax.persistence.Query query = em.createNativeQuery("SELECT T.* FROM GSTARTIB.P_TAGS T WHERE T.ADB_L_DELIVERY_STATUS = 'N'");
        return query.getResultList();
    }
}

我的困惑是,如果取消注释存储库中的第一个函数,它将正常运行并返回结果。

但是,当运行第二个函数时,我得到org.hibernate.MappingException: No Dialect mapping for JDBC type: -101错误,即使在我的application.properties文件中我声明了一种方言。

我在这里想念什么?

1 个答案:

答案 0 :(得分:0)

好吧,我发现了问题。

它给出的错误消息似乎使我误解,因为它与解决方案不匹配。

我还需要为createNativeQuery函数提供一个.class来转换结果。

em.createNativeQuery(<query>, PTags.class)解决了该问题