简体   繁体   English

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

[英]Spring Hibernate: No Dialect mapping for JDBC type: -101

I'm working on a spring-boot app and trying to build my repository, and am having an issue with Hibernate. 我正在开发一个春季启动应用程序,并试图构建我的存储库,并且Hibernate遇到了问题。

Pom dependencies: (there are more, just posting what i felt relevant) 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 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: 库:

//@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();
    }
}

My confusion is that, if I uncomment the first function in the repository, it will run and return results without any problem. 我的困惑是,如果我取消注释存储库中的第一个函数,它将运行并返回结果而没有任何问题。

But, when running the second function, I get: org.hibernate.MappingException: No Dialect mapping for JDBC type: -101 error even though in my application.properties file I have a dialect declared. 但是,当运行第二个函数时,我得到: org.hibernate.MappingException: No Dialect mapping for JDBC type: -101错误,即使在我的application.properties文件中我声明了一种方言。

What am I missing here? 我在这里想念什么?

Well, I found the problem. 好吧,我发现了问题。

The error message it gives seems misleading to me, as it doesn't match what the solution is. 它给出的错误消息似乎使我误解,因为它与解决方案不匹配。

I needed to provide the createNativeQuery function with a .class to cast the results too. 我还需要为createNativeQuery函数提供一个.class来转换结果。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM