• <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

        How can I get last inserted id using Hibernate(如何使用 Hibernate 获取最后插入的 id)

        <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  <legend id='qIjnC'><style id='qIjnC'><dir id='qIjnC'><q id='qIjnC'></q></dir></style></legend>
                  <tfoot id='qIjnC'></tfoot>

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

                      <tbody id='qIjnC'></tbody>
                    • <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>