我有两个表..资产表
ASSET_ID SYSIBM INTEGER 4 0 没有
USER_ID SYSIBM INTEGER 4 0 没有
ASSET_TYPE_ID SYSIBM SMALLINT 2 0 没有
ACCESSIBILITY_ID SYSIBM SMALLINT 2 0 是
DOWNLOAD_TYPE_ID SYSIBM SMALLINT 2 0 没有
ASSET_STATUS_ID SYSIBM SMALLINT 2 0 没有
ASSET_MARKETING_ID SYSPIIBM SMALLINT 2 0 是
ASSET_MARKETING_ID SYSPIIBM SMALLINT 2 0 是
和可访问性表
ACCESSIBILITY_ID SYSIBM SMALLINT 2 0 否
ACCESSIBILITY_DESC SYSIBM VARCHAR 50 0 否
我有两个豆子,
资产豆
@Column(name="ASSET_ID")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int assetId;
@Column(name="DATE_CREATED")
private Timestamp dateCreated;
@Column(name="LAST_UPDATED")
private Timestamp lastUpdated;
@Column(name="DATE_PUBLISHED")
private Timestamp datePublished;
@Column(name="ASSET_SURVEY")
private Short assetSurvey;
@Column(name="ASSET_HELP")
private Short assetHelp;
@Column(name="ACCEPTED_TERMS")
private Short acceptedTerms;
@Column(name="ASSET_DESC")
@Lob
private String assetDesc;
@Column(name="ASSET_ALIAS")
private String assetAlias;
@Column(name="ASSET_TITLE")
private String assetTitle;
@Column(name="ASSET_SUMMARY")
private String assetSummary;
@Column(name="ASSET_URL")
private String assetUrl;
@Column(name="ASSET_ORIGINALITY")
private Short assetOriginality;
@Column(name="ASSET_INVENTION")
private Short invationDisclosure;
@Column(name="ASSET_PRIVACY")
private String privacyCompliance;
@ManyToOne
@JoinColumn(name="ASSET_PI_SPI_ID")
private AssetPiSpi assetPiSpiId;
@ManyToOne
@JoinColumn(name="ASSET_MARKETING_ID")
@ForeignKey
private AssetMarketing assetMarketingId;
@ManyToOne(cascade=CascadeType.REMOVE,fetch=FetchType.LAZY)
@JoinColumn(name="ACCESSIBILITY_ID")
@ForeignKey
private Accessibility accessibilityId;
和可访问性
@Column(name="ACCESSIBILITY_ID")
private short accessibilityId;
@Column(name="ACCESSIBILITY_DESC")
private String accessibilityDesc;
@OneToMany(mappedBy="accessibilityId",cascade=CascadeType.REMOVE,fetch=FetchType.LAZY)
private Set<Asset> assetCollection;
当在我的 ManagerBean 中调用 EntitiManager.flush()
em.persist(asset);
em.flush();
我正进入(状态
javax.ejb.EJBException:见嵌套异常;嵌套异常是:org.apache.openjpa.persistence.InvalidStateException:在生命周期状态中遇到非托管对象“com.ibm.tap.ejb.dao.entity.Accessibility@169e3455”,同时通过字段“com.ibm.tap”级联持久性.ejb.dao.entity.Asset.accessibilityId" 在刷新期间。但是,该字段不允许级联持续存在。您不能刷新与非托管对象具有持久关联的非托管对象或图形。建议的操作:a) 将此字段的 cascade 属性设置为 CascadeType.PERSIST 或 CascadeType.ALL(JPA 注释)或“persist”或“all”(JPA orm.xml),b)全局启用 cascade-persist,c)手动在刷新之前保留相关的字段值。d) 如果引用属于另一个上下文,通过设置 StoreContext.setAllowReferenceToSiblingContext() 允许对其进行引用。失败对象:com.ibm.tap.ejb.dao.entity.Accessibility@169e3455
我尝试将资产类更改为
@ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)
@JoinColumn(name="ACCESSIBILITY_ID")
@ForeignKey
private Accessibility accessibilityId;
当我这样做时,我得到 javax.ejb.EJBException: See nested exception; 嵌套异常是:org.apache.openjpa.persistence.EntityExistsException:此上下文中已存在具有 oid“1”的“com.ibm.tap.ejb.dao.entity.Accessibility”类型的对象;另一个不能持久。失败对象:com.ibm.tap.ejb.dao.entity.Accessibility@166c27b9
这对我来说很有意义,我试图坚持我已经拥有的表格。我究竟做错了什么?