I'm using the interface CRUDRepository in order to use the save method in other class where Repository is injected.
This method does an insert and a select for retrieve this object inserted from database, I mean.
The query executed is quite simple:
select auditoriab0_.adb_seqitm as adb_seqitm1_1_0_,
auditoriab0_.adb_codprv as adb_codprv2_1_0_, auditoriab0_.adb_ideses as adb_ideses3_1_0_,
auditoriab0_.adb_locata as adb_locata4_1_0_, auditoriab0_.adb_rqores as adb_rqores5_1_0_,
auditoriab0_.adb_rstime as adb_rstime6_1_0_, auditoriab0_.adb_subprv as adb_subprv7_1_0_,
auditoriab0_.adb_swierr as adb_swierr8_1_0_, auditoriab0_.adb_tiptrz as adb_tiptrz9_1_0_,
auditoriab0_.adb_ubitrz as adb_ubitrz10_1_0_, auditoriab0_.adb_xmltxt as adb_xmltxt11_1_0_
from nwt00.auditoria_bus_gsi auditoriab0_ where auditoriab0_.adb_seqitm=:p1
Where adb_seqitm
column has and index on it (It's the table's primary key).
If this query is executed on SQLDeveloper, for instance, the explain plan is the correct one (access by rowid).
However, if this query is executed by hibernate, the result is a full scan.
Could you help me with this issue? I will be grateful because I don't have seen a real solution on internet for this specific problem.
Thank you in advance.
This behaviour happens with the ucp (universal connection pool) pool. My database bean configuration is the next (variables are setted by application.properties file):
UniversalConnectionPoolManager mgr;
try {
mgr = UniversalConnectionPoolManagerImpl. getUniversalConnectionPoolManager();
mgr.destroyConnectionPool("hotels");
} catch (UniversalConnectionPoolException e) {
}
PoolDataSourceImpl poolDataSource = (PoolDataSourceImpl) PoolDataSourceFactory.getPoolDataSource();
poolDataSource.setUser(userName);
poolDataSource.setPassword(passWord);
poolDataSource.setURL(url);
poolDataSource.setConnectionFactoryClassName(driver);
poolDataSource.setConnectionPoolName("hotels");
poolDataSource.setInitialPoolSize(initialNumConnections);
poolDataSource.setMinPoolSize(minNumConnections);
poolDataSource.setMaxPoolSize(maxNumConnections);
poolDataSource.setMaxConnectionReuseTime(reconnectTime);
poolDataSource.setMaxConnectionReuseCount(maxReconnectCount);
poolDataSource.setTimeToLiveConnectionTimeout(timeToLive);
poolDataSource.setConnectionWaitTimeout(connectWaitTimeOut);
poolDataSource.setValidateConnectionOnBorrow(true);
poolDataSource.setInactiveConnectionTimeout(inactiveConnectionTimeOut);
Properties properties = new Properties();
properties.put("v$session.program", "xxxx");
properties.put("defaultNChar", "false");
poolDataSource.setConnectionProperties(properties );
I'm using Spring Boot + Spring Data JPA. These are my dependencies of my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ucp</artifactId>
<version>11.2.0.4.0</version>
</dependency>
@krokodilko As you anticipated, the error was between database type and java type. In DDBB, this field is a String (varchar2(15)). In Java, this field is mapped with a long type. I guess hibernate or database is doing a conversion which breaks the index. I have changed the java type by String type and query is working successfully. Explain plan is correct.