Loading [Contrib]/a11y/accessibility-menu.js
Back
Close

Hibernate Native SQL

vembubalaji
16.8K views

Adding scalars

  • To avoid the overhead of using ResultSetMetadata, or simply to be more explicit in what is returned, we use scalars while creating Native Queries
A quick sample. Check out the JAVA class and SQL file
// { autofold
package com.tu.nativesqlsample;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.Session;
import org.hibernate.type.IntegerType;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • In this case, only domain_id and domainName would be returned back, though, we have requested for * from the table.
  • Also, we would still be returned with an array of Object – List<Object[]>, but now it will not use the ResultSetMetadata to determine the type of columns, but will instead explicitly get the domain_id, and domainName column as respectively a Integer, and a String from the underlying resultset.
  • Adding scalars to native Queries is preferable, considering the reduced overhead on the ResultSetmetaData and a marginal improvement on the performance.
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants