在简单的单向 OneToOne 映射中初始化依赖对象
我对简单的单向映射有疑问。以下是我的实体:
@Entity
public class Account extends UUIDBase {
private Profile profile;
@OneToOne(cascade = CascadeType.ALL, optional = false)
public Profile getProfile() {
return profile;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
}
@Entity
public class Profile extends UUIDBase {
...
}
每个帐户都必须分配一个配置文件。该帐户应该是映射的拥有方。初始化 dependentt Profile 属性的最佳位置在哪里?我尝试在帐户实体的构造函数中初始化配置文件,但这不起作用。
I have a problem with a simple unidirectional mapping. Here are my entities:
@Entity
public class Account extends UUIDBase {
private Profile profile;
@OneToOne(cascade = CascadeType.ALL, optional = false)
public Profile getProfile() {
return profile;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
}
@Entity
public class Profile extends UUIDBase {
...
}
Each account must have a Profile assigned. The account should be the owning side of the mapping. Where is the best place to initialize the dependendt Profile attribute? I tried to initialize the profile in the constructor of the Account entity but this doesn´t work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在构造函数中初始化它,但在应用程序或工厂中设置它可能会更好。
什么不起作用,你得到什么错误?
You could initialize it in the constructor, but setting it in the application or a factory may be better.
What does not work, what error do you get?