createSQLQuery in hibernate uses Prepared Statement?

前端 未结 2 1858
刺人心
刺人心 2021-01-12 10:29

I\'m using createSQLQuery with setString (No hard coded value) in Hibernate. I want to know that is Hibernate uses PreparedStatement f

2条回答
  •  不要未来只要你来
    2021-01-12 11:14

    I have tried to execute a query using Hibernates' createSQLQuery method then it will give me exception as below :-

    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    

    From the above exception we can see that it will try to execute com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275) internally.

    I have also found a question by @Alex Serna at Hibernate createSQLQuery parameter substitution where Alex also get the exception while trying to substitute table name.

    Observing stack trace I think Hibernate uses PreparedStatement for createSQLQuery internally.

提交回复
热议问题