我正在用JPA和Postgres db编写服务。我有一个名为Student的课程:
public class LeftNavAdapter : ExpandableRecyclerAdapter<LeftNavParentViewHolder, LeftNavChildViewHolder>
{
public override LeftNavChildViewHolder OnCreateChildViewHolder(ViewGroup childViewGroup)
{
var view = _inflater.Inflate(Resource.Layout.left_nav_item_child, childViewGroup, false);
return new LeftNavChildViewHolder(view, OnChildClick);
}
void OnChildClick(int position)
{
// Do whatever you want
}
}
还有一个电话课:
public class Student {
@id
private String id;
private String firstName;
private String lastName;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "student_phone", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "phone_id"))
private Set<Phone>;
// Setter and Getter
}
现在我的数据库中将有三个表,其中包含以下列:
现在,每当我从数据库中查询学生时,结果都包含相应的电话。我可以在学生表中获取内容吗?有时候我不想扩展学生的电话信息。
答案 0 :(得分:0)
使用延迟加载
if(val==="")...
或
编写本机查询
答案 1 :(得分:0)
@OneToMany是默认的懒惰提取
我假设您使用REST服务:
如果您在JAXB中使用@XmlTransient
:
@XmlTransient
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "student_phone", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "phone_id"))
private Set<Phone>;
或者如果您使用json,则可以添加此@JsonIgnore