我正在尝试使用以下代码保存QComputer的LinkedList:
public void saveOrUpdateAll(Collection list) {
final Session ses = getTxManager().getSessionFactory().getCurrentSession();
list.stream().forEach((object) -> {
ses.saveOrUpdate(object);
});
ses.flush();
}
,如果 QComputer 中的变量 planServices (表services_to_ip)不为空,则获取异常,否则数据存储在表ip_to_unit中:
[IllegalArgumentException occurred calling getter of ru.apertum.qsystem.server.model.QComputer.ip]
(org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of ru.apertum.qsystem.server.model.QComputer.ip)
SQL:
at ru.apertum.qsystem.client.forms.FAdmin.saveConfiguration(FAdmin.java:1910)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.Event
DispatchThread.run(EventDispatchThread.java:82)
public QComputer() { } private Long id; @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } private String ip; public void setIp(String ip) { this.ip = ip; } @Column(name = "ip") public String getIp() { return ip; } private Integer unitId; public void setUnitId(Integer unitId) { this.unitId = unitId; } @Column(name = "unit_id") public Integer getUnitId() { return unitId; } private String name; public void setName(String name) { this.name = name; } @Column(name = "name") public String getName() { return name; } @Column(name = "deleted") @Temporal(javax.persistence.TemporalType.DATE) private Date deleted; public Date getDeleted() { return deleted; } public void setDeleted(Date deleted) { this.deleted = deleted; } private List<QPlanService> planServices = new ArrayList<>(); public void setPlanServices(List<QPlanService> planServices) { this.planServices = planServices; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @JoinColumn(name = "ip", insertable = true, nullable = false, updatable = true, referencedColumnName="ip") @Fetch(FetchMode.SELECT) public List<QPlanService> getPlanServices() { return planServices; }
public QPlanService() {} private Long id; @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } private QService service; @OneToOne(targetEntity = QService.class) public QService getService() { return service; } public void setService(QService service) { this.service = service; } private String ip; @Column(name = "ip", insertable = false, updatable = false) public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; }
为什么会出现此错误?我认为解决问题的方法很简单,但我不明白原因。任何帮助都会很好。