簡體   English   中英

“IDENTITY_INSERT”設置為 OFF NETBEANS SQL

[英]"IDENTITY_INSERT" is set to OFF NETBEANS SQL

我將 Netbeans 與本地數據庫一起使用。 在服務-> 表或 SQL Managament Studio 中添加(插入)執行命令后,一切都很好。 使用“set identity_insert dbo.table1 on”后的工作。

但是當我運行項目時(單擊綠色的開始三角形按鈕),我只能看到數據(從 table1 中選擇 *)或刪除。 添加(插入)產生此問題:

org.eclipse.persistence.exceptions.DatabaseException 內部異常:com.microsoft.sqlserver.jdbcZ.SQLServerException:無法在表中插入顯式的 IDENT 值時的標識列錯誤代碼:544

這是負責添加到基礎的代碼:

Project p = new Project();
ValuePro vp = new ValuePro(Integer.parseInt(idField.getText()),titleField.getText(), descField.getText());
p.save(vp);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("project");
        
        EntityManager em=emf.createEntityManager();
        em.getTransaction().begin();
        try{
            em.persist(values);
            em.getTransaction().commit();

“Set identity_insert dbo.table1 on”對項目沒有影響。 有沒有人有類似的問題並有解決方案?

我找到了答案。 我意識到表中的 id(Netbeans -> Services -> dbo -> Tables -> table1 -> id)在 DB 數據類型中具有值“int identity”。 我刪除了該表並重新創建了它(在 Netbeans 中。不在 SQL Management Studio 中,當我在 SQLMS 中嘗試相同時。它不起作用)。 這次該表創建了一個沒有標識的 id int。 一切正常!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM