• <legend id='IXT9L'><style id='IXT9L'><dir id='IXT9L'><q id='IXT9L'></q></dir></style></legend>

        <bdo id='IXT9L'></bdo><ul id='IXT9L'></ul>
    1. <small id='IXT9L'></small><noframes id='IXT9L'>

    2. <tfoot id='IXT9L'></tfoot>

      1. <i id='IXT9L'><tr id='IXT9L'><dt id='IXT9L'><q id='IXT9L'><span id='IXT9L'><b id='IXT9L'><form id='IXT9L'><ins id='IXT9L'></ins><ul id='IXT9L'></ul><sub id='IXT9L'></sub></form><legend id='IXT9L'></legend><bdo id='IXT9L'><pre id='IXT9L'><center id='IXT9L'></center></pre></bdo></b><th id='IXT9L'></th></span></q></dt></tr></i><div id='IXT9L'><tfoot id='IXT9L'></tfoot><dl id='IXT9L'><fieldset id='IXT9L'></fieldset></dl></div>

        如何使用 Hibernate 获取最后插入的 id

        时间:2023-09-24

        <legend id='nnAJS'><style id='nnAJS'><dir id='nnAJS'><q id='nnAJS'></q></dir></style></legend>

          1. <small id='nnAJS'></small><noframes id='nnAJS'>

            • <i id='nnAJS'><tr id='nnAJS'><dt id='nnAJS'><q id='nnAJS'><span id='nnAJS'><b id='nnAJS'><form id='nnAJS'><ins id='nnAJS'></ins><ul id='nnAJS'></ul><sub id='nnAJS'></sub></form><legend id='nnAJS'></legend><bdo id='nnAJS'><pre id='nnAJS'><center id='nnAJS'></center></pre></bdo></b><th id='nnAJS'></th></span></q></dt></tr></i><div id='nnAJS'><tfoot id='nnAJS'></tfoot><dl id='nnAJS'><fieldset id='nnAJS'></fieldset></dl></div>

                <bdo id='nnAJS'></bdo><ul id='nnAJS'></ul>
                  <tfoot id='nnAJS'></tfoot>
                    <tbody id='nnAJS'></tbody>
                  本文介绍了如何使用 Hibernate 获取最后插入的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 Hibernate 中获取最后插入的值的 id.

                  搜索后:

                  Long lastId = ((Long) session.createSQLQuery("SELECT LAST_INSERT_ID()").uniqueResult()).longValue();

                  但是下面的代码给了我这个错误:

                  <块引用>

                  java.lang.ClassCastException: java.math.BigInteger 无法转换为 java.lang.Long

                  请分享你的想法!

                  解决方案

                  Long lastId = ((BigInteger) session.createSQLQuery("SELECT LAST_INSERT_ID()").uniqueResult()).longValue();

                  别忘了导入:

                  <块引用>

                  导入 java.math.BigInteger;

                  解决方案

                  错误很明显.它正在返回 BigInteger 而不是 long

                  您必须将其分配给 大整数.并从中获取 longValue().p>

                  I want to fetch the last inserted value's id in Hibernate.

                  After search:

                  Long lastId = ((Long) session.createSQLQuery("SELECT LAST_INSERT_ID()").uniqueResult()).longValue();
                  

                  But the following code gives me this error:

                  java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

                  Please share your thoughts!

                  Solution

                  Long lastId = ((BigInteger) session.createSQLQuery("SELECT LAST_INSERT_ID()").uniqueResult()).longValue();
                  

                  Don't forget to import:

                  import java.math.BigInteger;

                  解决方案

                  Error is pretty clear. It's returning BigInteger and not long

                  You have to assign it to a BigInteger. And get longValue() from it.

                  这篇关于如何使用 Hibernate 获取最后插入的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:处理 FreeMarker 模板中的错误有哪些不同的方法? 下一篇:如何在字符串数组中获取 Logger 值

                  相关文章

                  <legend id='qIjnC'><style id='qIjnC'><dir id='qIjnC'><q id='qIjnC'></q></dir></style></legend>
                1. <tfoot id='qIjnC'></tfoot>

                2. <small id='qIjnC'></small><noframes id='qIjnC'>

                    • <bdo id='qIjnC'></bdo><ul id='qIjnC'></ul>

                      <i id='qIjnC'><tr id='qIjnC'><dt id='qIjnC'><q id='qIjnC'><span id='qIjnC'><b id='qIjnC'><form id='qIjnC'><ins id='qIjnC'></ins><ul id='qIjnC'></ul><sub id='qIjnC'></sub></form><legend id='qIjnC'></legend><bdo id='qIjnC'><pre id='qIjnC'><center id='qIjnC'></center></pre></bdo></b><th id='qIjnC'></th></span></q></dt></tr></i><div id='qIjnC'><tfoot id='qIjnC'></tfoot><dl id='qIjnC'><fieldset id='qIjnC'></fieldset></dl></div>