(I posted this in stackoverflow ( java - Hibernate5/javax.persistence vs Hibernate6/jakarta.persistence - Stack Overflow ) but had no answers yet - I wondered whether anyone on here has had a similar issue with upgrading?)
I’ve run into an interesting difference between the above two combinations.
In my code I have something like:
//deals with setting null values in parameterised queries
private static void setTValue(Query aQ,String aCol,LocalTime aValue)
{
try
{
if (aValue == null)
{
//for javax
aQ.setParameter(aCol,aValue,TemporalType.TIME);
//for jakarta
// aQ.setParameter(aCol,null);
}
else
{
java.sql.Time t = java.sql.Time.valueOf(aValue);
aQ.setParameter(aCol,t);
}
}
catch (Exception e)
{
LOG.error("Error converting time value", e);
}
}
and then, elsewhere:
org.hibernate.query.Query myQuery = session.createNativeQuery("insert into dbo.mytable (TimeCol) values (:TimeCol)");
setTValue(myQuery,"TimeCol",aLocalTimeValue);
myQuery.executeUpdate();
I’m using Azure (i.e. cloud version of SQL Server) and TimeCol is of type TIME. This code is used 100s of times in a loop for inserting records. Now, if I use Hibernate 5 (5.6.9.Final) and javax.persistence-api (2.2), along with the line marked “for javax” above, this runs at a certain speed. If I switch to Hibernate 6 (6.0.1.Final) and jakarta.persistence-api (3.1.0), along with the line marked “for jakarta” above, it runs at something like a quarter of the speed.
I can’t work out whether this is due to some change in Hibernate 6 (which claims performance improvements!), or in the switch from javax 2 to jakarta 3.
(Yes, I know the insert could be done using a POJO instead of a native query, but I’d rather not go through changing all that right now - unless that would give a distinct performance improvement? Although I would have thought a native query would inherently be faster than going through Hibernate’s objects? I’m just interested in why there should be such a noticeable difference between Hibernate 5/6 and javax 2/jakarta 3.)