gpt4 book ai didi

java - 无法刷新非托管对象

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:39:33 25 4
gpt4 key购买 nike

我要刷新 Eleve 的列表从数据库到 Jtable。Jtable它的自身绑定(bind)到一个可观察的 list< Eleve > , 因此列表中的任何添加/删除都会在 Jtable 中自动更新.

我的代码 self 解释:

EleveJpaController ejc = new EleveJpaController(emf);
java.util.Collection<Eleve> data = ejc.findEleveByNiveauClasseNomPrenom(niv, classe, nom, prenom);

for (Eleve entity : data) {
entityManager.refresh(entity);
}

list.clear();
list.addAll(data);

列表< Eleve > findEleveByNiveauClasseNomPrenom(a,v,x,n):

 public List<Eleve> findEleveByNiveauClasseNomPrenom(String niv,String classe,String nom, String prenom)
{
EntityManager em = getEntityManager();
Query qr= em.createQuery("SELECT e FROM Eleve e WHERE e.niv.niv like '%"+niv+"%' and e.class1.libelle like '%"+classe+"%' and e.nom like '%"+nom+"%' and e.prenom like '%"+prenom+"%'");

return qr.getResultList();
}

如您所见,它是 Eleve 的管理良好的列表对象..那么为什么抛出这个异常?

[EL Info]: 2013-12-02 13:25:33.312--ServerSession(1903253526)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Info]: 2013-12-02 13:25:35.005--ServerSession(1903253526)--file:/C:/Users/marwen/Documents/NetBeansProjects/JocondeFinale/build/classes/_JocondeFinalePU login successful
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Can not refresh not managed object: entities.Eleve[ idEleve=7 ].
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.refresh(EntityManagerImpl.java:943)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.refresh(EntityManagerImpl.java:849)
at entities.GestionPaiement.niveauJcbbxItemStateChanged(GestionPaiement.java:736)
at entities.GestionPaiement.access$2000(GestionPaiement.java:32)
at entities.GestionPaiement$FormListener.itemStateChanged(GestionPaiement.java:607)
at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1225)
at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1273)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1329)
at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:94)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:578)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

干杯。

最佳答案

您可能使用不同的 EntityManager 来刷新您的实体,而不是使用从数据库加载实体的 EntityManager。实体不在新的 EntityManager 中管理。根据javadoc ,异常是非托管实体的正常行为。使用相同的 EntityManager,或使用 merge()使您的对象得到管理

关于java - 无法刷新非托管对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20328740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com