gpt4 book ai didi

mysql - 从现有对象创建新对象

转载 作者:行者123 更新时间:2023-11-29 23:59:29 26 4
gpt4 key购买 nike

我有两个实体:Participante 和 Emitente。发射者扩展了参与者。

例如:

@Entity
@Cacheable(true)
@Default
@Table(name = "participantes")
@Inheritance(strategy = InheritanceType.JOINED)
public class Participante implements IEntity {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Size(max = 10)
@Column(name = "codigo", nullable = true, length = 20)
private String codigo;
...
}

@Entity
@Cacheable(true)
@Any
@Table(name = "emitentes")
public class Emitente extends Participante {

//other methods and properties

}

在我的应用程序中,我有两个屏幕条目,一个用于注册参与者,一个用于注册 Emitentes。问题是,在某些情况下,我需要从已经存在的 Participante 创建一个新的 Emitente。

例如:我签署了一个Participante,保存在数据库中以及所有内容,我决定有一个Emitente。然后我进入 Emitente 屏幕并将 Participante 拉到其中,添加与 Emitente 相关的其他属性,然后单击“保存”。

有没有办法自动执行此操作,或者我是否必须在数据库中手动设置属性?

或者更确切地说,Hibernate 可以为我做到这一点?

如果有人不能理解我,请知道我会尽力解释得更好。

感谢大家,抱歉我的英语不是最好的!

<小时/>

为了更好地解释我创建的示例应用程序,可以从以下链接下载: Aplicaçao

要运行它,只需使用 NetBeans 并创建一个名为“testeHeranca”的 MySql DB,这种方式更好解释。

谢谢大家。

最佳答案

(抱歉还不能发表评论)

您必须初始化 Emitente。这是 Emitente 表中的全新条目。

在 Emitente 中,只需创建一个接受 Participante 对象的构造函数,并基于该对象创建 Emitente。

关于mysql - 从现有对象创建新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145224/

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