I'm working on a spring-boot app and trying to build my repository, and am having an issue with Hibernate.
Pom dependencies: (there are more, just posting what i felt relevant)
<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:
//@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.
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.
em.createNativeQuery(<query>, PTags.class)
fixed the issue
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.