- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
null or transient value"。我被困住了,不知道该怎么办-6ren"> null or transient value"。我被困住了,不知道该怎么办-Here you can see the entity-relationship diagram of my database with associations 我正在 NetBeans 中使用 A-6ren">
Here you can see the entity-relationship diagram of my database with associations
我正在 NetBeans 中使用 Apache Derby 开发 Hibernate 库存管理程序。该应用程序将要求用户从合作伙伴数据库中预先输入的项目/合作伙伴中进行选择,并输入日期(请参阅上面的 ERD)。用户可以选择元素是从库存中入库还是出库。据说这会在 Advicenote 表中创建一个 Advicenote 条目,如下所示:
然后在下一个窗口中,用户将能够实际设置与 Advicenote 关联的交易值:
下面是实现此功能的监听器代码:
private void deliveryButtonActionPerformed(java.awt.event.ActionEvent evt) {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
advice.setAdvicedate((Date) this.dateSpinner.getValue());
advice.setInOrOut((short)1);
Criteria criteria = session.createCriteria(Partner.class);
partner = (Partner) criteria.add(Restrictions.eq("partnerName", this.partnerComboBox.getSelectedItem())).uniqueResult();
System.out.println("partner");
advice.setPartner(partner);
session.save(advice);
transaction.commit();
session.close();
delivery.setVisible(true);
}
private void transferButtonActionPerformed(java.awt.event.ActionEvent evt) {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
advice.setAdvicedate((Date) this.dateSpinner.getValue());
advice.setInOrOut((short)-1);
Criteria criteria = session.createCriteria(Partner.class);
partner = (Partner) criteria.add(Restrictions.eq("partnerName", this.partnerComboBox.getSelectedItem().toString())).uniqueResult();
advice.setPartner(partner);
session.save(advice);
transaction.commit();
session.close();
transfer.setVisible(true);
}
以下是类的 XML 映射文件:
合作伙伴类别
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Partner" table="PARTNER" schema="APP">
<id name="partnerId" type="int">
<column name="PARTNER_ID"/>
<generator class="native"/>
</id>
<property name="partnerName" type="string" column="PARTNER_NAME" length="100"/>
<set name="advicenotes" table="ADVICENOTE" inverse="false" cascade="all" lazy="true" fetch="select">
<key column="PARTNER_ID" not-null="true"/>
<one-to-many class="classes.Advicenote" />
</set>
</class>
</hibernate-mapping>
建议类
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 9, 2019, 3:57:52 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
<class name="classes.Advicenote" table="ADVICENOTE" schema="APP" optimistic-lock="version">
<id name="advicenoteId" type="int" column="ADVICENOTE_ID">
<generator class="native" />
</id>
<property name="advicedate" type="date" column="ADVICE_DATE" length="10" />
<property name="inOrOut" type="java.lang.Short" column="IN_OR_OUT" />
<many-to-one
name="partner" class="classes.Partner"/>
<set name="transactions" table="TRANSACTIONS" inverse="false" cascade="all" lazy="true" fetch="select">
<key column="ADVICENOTE_ID" not-null="true"/>
<one-to-many class="classes.Transactions"/>
</set>
</class>
</hibernate-mapping>
但是,我收到此错误:
Exception in thread "AWT-EventQueue-0" org.hibernate.PropertyValueException: not-null property references a null or transient value : classes.Advicenote._classes.Partner.advicenotesBackref at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:111) at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:55) at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:115) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:645) at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:282) at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:263) at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:317) at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:332) at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:196) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:127) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192) at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177) at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73) at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:713) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:705) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:700) at delivery.view.Selection.deliveryButtonActionPerformed(Selection.java:190) at delivery.view.Selection$2.actionPerformed(Selection.java:106) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6632) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342) at java.desktop/java.awt.Component.processEvent(Component.java:6397) at java.desktop/java.awt.Container.processEvent(Container.java:2263) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
多年来我一直在尝试解决这个问题,但没有成功。我会提供每一个帮助!
最佳答案
您已定义双向映射,但仅设置一侧。
您必须在AdviceNote
中设置partner
,并填写在Partner
上设置的advicenotes
:
advice.setPartner(partner);
partner.getAdviceNotes().add(advice);
session.save(advice);
transaction.commit();
关于java - hibernate 异常 "PropertyValueException: not-null property references a > null or transient value"。我被困住了,不知道该怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54765791/
我是一名优秀的程序员,十分优秀!