久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      1. <small id='78j61'></small><noframes id='78j61'>

        <legend id='78j61'><style id='78j61'><dir id='78j61'><q id='78j61'></q></dir></style></legend>

      2. 如何使用 JPA 注釋注釋 MYSQL 自動(dòng)增量字段

        How to annotate MYSQL autoincrement field with JPA annotations(如何使用 JPA 注釋注釋 MYSQL 自動(dòng)增量字段)
      3. <small id='aNcJv'></small><noframes id='aNcJv'>

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

          • <legend id='aNcJv'><style id='aNcJv'><dir id='aNcJv'><q id='aNcJv'></q></dir></style></legend>
                <bdo id='aNcJv'></bdo><ul id='aNcJv'></ul>
                    <tbody id='aNcJv'></tbody>
                  <tfoot id='aNcJv'></tfoot>

                  本文介紹了如何使用 JPA 注釋注釋 MYSQL 自動(dòng)增量字段的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  直截了當(dāng),問題是將對象運(yùn)算符保存到 MySQL 數(shù)據(jù)庫中.在保存之前,我嘗試從該表中進(jìn)行選擇,它可以正常工作,與 db 的連接也是如此.

                  Straight to the point, problem is saving the object Operator into MySQL DB. Prior to save, I try to select from this table and it works, so is connection to db.

                  這是我的 Operator 對象:

                  Here is my Operator object:

                  @Entity
                  public class Operator{
                  
                     @Id
                     @GeneratedValue
                     private Long id;
                  
                     private String username;
                  
                     private String password;
                  
                  
                     private Integer active;
                  
                     //Getters and setters...
                  }
                  

                  為了保存,我使用 JPA EntityManagerpersist 方法.

                  To save I use JPA EntityManager’s persist method.

                  這是一些日志:

                  Hibernate: insert into Operator (active, password, username, id) values (?, ?, ?, ?)
                  com.mysql.jdbc.JDBC4PreparedStatement@15724a0: insert into Operator (active,password, username, id) values (0, 'pass', 'user', ** NOT SPECIFIED **)
                  

                  在我看來,問題是自動(dòng)遞增的配置,但我不知道在哪里.

                  The way I see it, problem is configuration with auto increment but I can't figure out where.

                  嘗試了一些我在這里看到的技巧:Hibernate 不尊重 MySQL auto_increment 主鍵字段 但什么也沒有其中的工作

                  Tried some tricks I've seen here: Hibernate not respecting MySQL auto_increment primary key field But nothing of that worked

                  如果需要任何其他配置文件,我會(huì)提供.

                  If any other configuration files needed I will provide them.

                  DDL:

                  CREATE TABLE `operator` ( 
                  `id` INT(10) NOT NULL AUTO_INCREMENT,
                  `first_name` VARCHAR(40) NOT NULL,
                  `last_name` VARCHAR(40) NOT NULL,
                  `username` VARCHAR(50) NOT NULL,
                  `password` VARCHAR(50) NOT NULL,
                  `active` INT(1) NOT NULL,
                  PRIMARY KEY (`id`)
                  )
                  

                  推薦答案

                  要使用 MySQL AUTO_INCREMENT 列,您應(yīng)該使用 IDENTITY 策略:

                  To use a MySQL AUTO_INCREMENT column, you are supposed to use an IDENTITY strategy:

                  @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
                  private Long id;
                  

                  在 MySQL 中使用 AUTO 會(huì)得到什么:

                  Which is what you'd get when using AUTO with MySQL:

                  @Id @GeneratedValue(strategy=GenerationType.AUTO)
                  private Long id;
                  

                  實(shí)際上相當(dāng)于

                  @Id @GeneratedValue
                  private Long id;
                  

                  換句話說,您的映射應(yīng)該可以工作.但是 Hibernate 應(yīng)該省略 SQL 插入語句中的 id 列,而事實(shí)并非如此.一定有某種不匹配的地方.

                  In other words, your mapping should work. But Hibernate should omit the id column in the SQL insert statement, and it is not. There must be a kind of mismatch somewhere.

                  您是否在 Hibernate 配置中指定了 MySQL 方言(可能是 MySQL5InnoDBDialectMySQL5Dialect,具體取決于您使用的引擎)?

                  Did you specify a MySQL dialect in your Hibernate configuration (probably MySQL5InnoDBDialect or MySQL5Dialect depending on the engine you're using)?

                  另外,誰創(chuàng)建了這個(gè)表?可以顯示對應(yīng)的DDL嗎?

                  Also, who created the table? Can you show the corresponding DDL?

                  跟進(jìn):我無法重現(xiàn)您的問題.使用 your 實(shí)體的代碼和 your DDL,Hibernate 使用 MySQL 生成以下(預(yù)期的)SQL:

                  Follow-up: I can't reproduce your problem. Using the code of your entity and your DDL, Hibernate generates the following (expected) SQL with MySQL:

                  insert 
                  into
                      Operator
                      (active, password, username) 
                  values
                      (?, ?, ?)
                  

                  請注意,如預(yù)期的那樣,上述語句中缺少 id 列.

                  Note that the id column is absent from the above statement, as expected.

                  總而言之,您的代碼、表格定義和方言是正確且連貫的,它應(yīng)該可以工作.如果它不適合您,則可能某些內(nèi)容不同步(進(jìn)行干凈的構(gòu)建,仔細(xì)檢查構(gòu)建目錄等)或其他錯(cuò)誤(檢查日志是否有任何可疑內(nèi)容).

                  To sum up, your code, the table definition and the dialect are correct and coherent, it should work. If it doesn't for you, maybe something is out of sync (do a clean build, double check the build directory, etc) or something else is just wrong (check the logs for anything suspicious).

                  關(guān)于方言,MySQL5DialectMySQL5InnoDBDialect唯一的區(qū)別在于后者添加了ENGINE=InnoDB生成 DDL 時(shí)到表對象.使用其中一種不會(huì)更改生成的 SQL.

                  Regarding the dialect, the only difference between MySQL5Dialect or MySQL5InnoDBDialect is that the later adds ENGINE=InnoDB to the table objects when generating the DDL. Using one or the other doesn't change the generated SQL.

                  這篇關(guān)于如何使用 JPA 注釋注釋 MYSQL 自動(dòng)增量字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯(cuò)誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數(shù)的三元表達(dá)式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲(chǔ)出現(xiàn)的每個(gè)字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 char 原語?)

                    <bdo id='ugIdy'></bdo><ul id='ugIdy'></ul>
                      • <tfoot id='ugIdy'></tfoot>
                      • <small id='ugIdy'></small><noframes id='ugIdy'>

                            <tbody id='ugIdy'></tbody>

                            <i id='ugIdy'><tr id='ugIdy'><dt id='ugIdy'><q id='ugIdy'><span id='ugIdy'><b id='ugIdy'><form id='ugIdy'><ins id='ugIdy'></ins><ul id='ugIdy'></ul><sub id='ugIdy'></sub></form><legend id='ugIdy'></legend><bdo id='ugIdy'><pre id='ugIdy'><center id='ugIdy'></center></pre></bdo></b><th id='ugIdy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ugIdy'><tfoot id='ugIdy'></tfoot><dl id='ugIdy'><fieldset id='ugIdy'></fieldset></dl></div>
                            <legend id='ugIdy'><style id='ugIdy'><dir id='ugIdy'><q id='ugIdy'></q></dir></style></legend>
                            主站蜘蛛池模板: 国产精品久久久久久久久久久免费看 | 亚洲欧美日韩电影 | 伊人春色成人网 | 美国黄色毛片 | 天天综合久久 | 一区二区在线免费观看 | 国产精品精品久久久 | 国产精品久久久久久久免费大片 | 天天操夜夜操 | 国产午夜精品一区二区三区嫩草 | 亚洲精品久久久久国产 | 亚洲精品无 | 狠狠的操| 欧美性一区二区三区 | 国产激情一区二区三区 | 色吧久久 | 亚洲国产视频一区二区 | av日韩一区 | 亚洲精品乱码久久久久v最新版 | 在线亚洲欧美 | 超碰人人人 | 亚洲精品一区二区三区中文字幕 | 国产在线视频一区二区 | 二区在线视频 | 国产 亚洲 网红 主播 | 欧美精品欧美精品系列 | 成人午夜在线 | 国产人成精品一区二区三 | 精品久久久久久亚洲精品 | 久久久久国产精品 | 日日夜夜精品视频 | 逼逼视频| 又黑又粗又长的欧美一区 | 国产在线精品一区 | 国产高清在线观看 | 精品91| 日韩在线观看一区二区三区 | 日韩精品在线视频 | 久久国产精品一区二区三区 | 欧洲一级毛片 | 精品欧美一区二区三区久久久 |