- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试向基于 Java 的 Hibernate 应用程序添加字节码增强功能。 Hibernate 的版本是 5.2.6.Final,它是在 maven 中构建的,所以我使用 hibernate-enhance-maven-plugin.我已经测试了以下问题直至5.2.18.Final,但结果是相同的。
“enableAssociationManagement”选项给我带来了几个问题,并且应用程序无法增强。我的问题是我有几个单向 ManyToOne 映射,我只需要从子类访问父类。我永远不需要从父实体引用子实体。
我的典型映射如下所示:
public class Child implements Serializable {
private Parent parent;
@ManyToOne
@JoinColumn(name="FK_PARENT", referencedColumnName="ID", nullable=true)
public Parent getParent() { return this.parent; }
public void setParent(Parent parent) { this.parent = parent; }
}
public class Parent implements Serializable {
//No variable/getter/setter for a collection of the children, as they are not needed here.
}
所有这些映射在增强过程中都会失败,给出以下错误:
INFO: Enhancing [com.mycom.model.Child] as Entity
Aug 08, 2019 3:31:09 PM org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer handleBiDirectionalAssociation
INFO: Could not find bi-directional association for field [com.mycom.model.Child#parent]
我理解这个错误。我在父级中没有相应的 @OneToMany 注释。我已经确认这确实有效:
public class Child implements Serializable {
private Parent parent;
@ManyToOne
@JoinColumn(name="FK_PARENT", referencedColumnName="ID", nullable=true)
public Parent getParent() { return this.parent; }
public void setParent(Parent parent) { this.parent = parent; }
}
public class Parent implements Serializable {
private Set<Child> children;
@OneToMany(mappedBy="parent")
public Set<Child>getChildren() { return this.children; }
public void setChildren(Set<Child>parent) { this.children = children; }
}
但如前所述,我不想要一个。我目前的理解是 more efficient to only have a unidirectional @ManyToOne mapping (只是@ManyToOne)。但是,也许我错了,因为这个错误即将出现?
是否有更好的方法来注释我的两个模型实体?或者我是否缺少一个注释/选项来向字节码增强表明多对一关系完全是单向的,而不是双向的?
最佳答案
这只是一个信息级别的警告。
enableAssociationManagement 确定“是否应增强双向关联管理”。由于它是单向的,因此无需做任何工作。
当指定failOnError 时,这不会停止您的构建。
如果您查看 PersistentAttributesEnhancer 的源代码 PersistentAttributesEnhancer可以看到,当没有指定mappedBy时,会记录这个info级别的日志。
如果您的构建因您的failOnError 设置而失败,则很可能存在不同的问题。错误消息的描述性不是很强,看起来信息消息就是问题所在。我必须在 IllegalStateException 上放置异常断点才能确定真正的问题。
关于java - Hibernate 字节码增强单向 ManyToOne,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57421320/
一个雇主有几个雇员,因此雇员与他们的雇主有(多对一)关系。假设我们忽略了从雇主到雇员的反向关系(一对多),那么从雇员的角度来看,这可以表示为一对一的关系!? 最佳答案 乍一看,它可能看起来如此 - 使
因此,我研究了neo4j,由于它的数据模型可能非常适合我的项目,因此我可能会在下一个项目中使用它。我浏览了文档,但仍然需要这个问题的答案: 我可以将关系设置为单向吗? 看来neo4j人们喜欢看电影,所
我在用: Spring Boot Spring Data JPA Spring Data Rest hibernate 嵌入式H2数据库 我正在尝试定义 2 个类,First和 Second ,这样就
给定以下代码 public class Course { @Id @GeneratedValue private Long id; private String nam
我的帐户和组之间存在多对多关系。组表的数据已预先填充,无需添加其他组。 使用 Hibernate,我的愿望是: 将帐户添加到帐户表, 向 account_group 表添加一条记录,并且 不向组表中添
我有一个 SKSpriteNode 作为球,它的所有 SKPhysicsBody 属性都可以向各个方向移动。我现在想要的是使其单向(仅朝它之前未移动到的方向移动,并且不返回到它已移动的路径)。目前我对
我已经看到多个关于此功能可用于蓝牙 4.0/LE 的引用资料,但我不确定从哪里开始或如何实现它。 明确地说,我指的是真正的无连接,只有一台设备上有一个接收器,另一台设备上有一个发射器。 (或者,更具体
给定以下代码 public class Course { @Id @GeneratedValue private Long id; private String nam
我在删除单向 OneToMany 关系中的所有者对象时遇到问题。 相关的部分是我有三个对象:Acronym、Expansion 和 Tag。 Acronym 与 Expansion 具有单向 OneT
我已经基于 this 在 JavaScript 中实现了一个 ElGamal 方案(代码很糟糕,只是想快速测试一下)解释。 var forge = require('node-forge'); var
我在我的模型中应用领域驱动设计聚合模式。我遵循常见的 DDD 聚合模式示例:Order 是管理一个或多个 LineItem 的根聚合。在我在网络上找到的许多聚合模式示例中,LineItem 应该不知道
这是我的场景, 我有 SubForum 类,它包含一组主持人,该集的每个实体 int 都是 User 类。 这是子论坛的映射
我想保存/保留一个实体(父实体),该实体(父实体)具有仅由父对象包含的唯一子对象。一切正常,直到出现重复的 child ,在这里我得到以下异常: Caused by: com.mysql.jdbc.e
这是我为汉诺塔问题编写的 Python 代码,其中塔必须从左桩转移到中间桩,使用右桩作为备用: def hanoi(n, origin = "1", destination = "2", spare
我有几个单向 JPA2 @OnetoMany 关系的失败案例下面是代码片段 @Entity @Table(name="CUSTOMER") @Access(AccessType.FIELD) publ
我想构建 Hibernate OneToMany 关系,其中父级有一个复合主键,子级有一个主键(hibernate 自动生成)。以下是我的工作示例代码: class Parent{ @Embe
我的项目中有以下实体: AccountGroup AccountItem AccountSegment 具有以下关系: AccountGroup有List AccountItem 有 List 一切正
是否可以使用自动布局和界面生成器进行单向尺寸匹配? 例如,我可能有两个标签。我不希望标签 A 大于标签 B,我希望 B 具有其固有大小。但使用“匹配高度/宽度”可能会导致大量文本增加 A 的大小,从而
尝试使用 Weblogic 11g 设置单向 SSL 并遇到问题。我有一个自定义身份(我自己的证书),但我只想执行单向 SSL,那么为什么我需要指定信任 keystore ? (我没有使用信任,因为我
注意:这不是 this 的副本问题,因为我了解您何时会使用单向 channel 。我一直这样做。我的问题是为什么这个程序是有效的: func main() { ch := make(chan<
我是一名优秀的程序员,十分优秀!