jjzjj

OneToMany-association

全部标签

java - JPA 如何为 @OneToMany 关系的列添加唯一约束,如用户名

我有一个代表网站的Site类和一个User类。一个Site可以有多个User。classSite{privateintsite_ID;@OneToMany//withajointableprivateListusers;//...}classUser{privateintuser_ID;privateStringname;privateStringlastname;privateStringusername;privateStringpassword;}我想允许相同的用户名存在于所有站点上,但每个站点只能存在一个。Site/User/username1/1/username11/2/u

java - 当通过 gwt 将注释与 gilead 一起用于 hibernate 时,我遇到了 oneToMany 关联错误

我正在使用Gilead将我的实体保存在我的GWT项目中,我也在使用hibernate注释。我的问题出在我的onetomany关联上。这是我的用户类,它包含对FileLocations列表的引用@Entity@Table(name="yf_user_table")publicclassYFUserimplementsSerializable{@Id@GeneratedValue(strategy=GenerationType.AUTO)@Column(name="user_id",nullable=false)privateintuserId;@Column(name="username

java - 加入获取 : "query specified join fetching, but the owner of the fetched association was not present in the select list"

我有以下代码:publicclassValueDAOimplementsBusinessObject{privateLongid;privateStringcode;privateClassDAOclassDAO;....}publicListgetCodesByCodeClass(LongclassId){Stringselect="selectdistinctval.codefromValueDAOvalleft"+"joinfetchval.classDAO";Stringwhere="whereval.classDAO.id=?orderbyval.code";returnge

java - Spring Boot JPA - OneToMany 关系导致无限循环

我有两个具有简单@OneToMany关系的对象,如下所示:parent:@EntitypublicclassParentAccount{@Id@GeneratedValueprivatelongid;privateStringname;@OneToMany(fetch=FetchType.EAGER,mappedBy="parentAccount")privateSetlinkedAccounts;}child:@EntitypublicclassLinkedAccount{@Id@GeneratedValueprivatelongid;@ManyToOne(optional=fals

java - Spring Data Rest JPA - 无法延迟加载 OneToMany 双向关系

我有两个实体,Company和Job,具有OneToMany双向关系。我的问题是我不能延迟加载公司的Listjobs.例如当我这样做时:获取/api/companies/1这是JSON响应:{"id":1,"name":"foo",..."_embedded":{"jobs":[{...},...{...}],"employees":[{...},{...}]},"_links":{"self":{"href":"http://localhost:8080/api/companies/1"},"jobs":{"href":"http://localhost:8080/api/compa

java - @OneToMany 与@JoinTable 错误

我正在尝试用**@JoinTable**来理解**@OneToMany**我正在使用JPA2.1、Hibernate5.0.4和Oracle11XE。当我调用userDao.save(user)(下面的代码)时,我得到了java.sql.SQLIntegrityConstraintViolationException:ORA-00001:uniqueconstraint(HIBERNATE.USER2ORDER_PK)violated我做错了什么?谁能帮我理解一下?数据链接:DROPTABLEHIBERNATE.T_USER2ORDERS;DROPTABLEHIBERNATE.T_OR

java - Spring 数据休息 : Detected multiple association links with same relation type

关于这个问题,我查了一下SpringDataRestAmbiguousAssociationException但无法让它为我工作。正如您在下面的代码中看到的,我添加了@RestResource注释,其中rel等于其他值。与上面的问题类似,POST请求有效,但是GET请求抛出关于具有相同关系类型的多个关联链接的异常:"CouldnotwriteJSON:Detectedmultipleassociationlinkswithsamerelationtype!Disambiguateassociation@org.springframework.data.rest.core.annotat

java - JPA CriteriaQuery OneToMany

我有两个具有OneToMany关系的实体。为简单起见,我们假设它们是学校和学生,学校与学生之间存在单向关系。我想找到有特定学生的学校对象(具有特定年龄、姓名、ssn等的学生)。我知道我可以为简单的学校属性(对于学校名称,如下所示)创建一个简单的条件,如下所示:ParameterExpressionp=criteriaBuilder.parameter(String.class,"schoolName");criteria=criteriaBuilder.and(criteria,criteriaBuilder.like(schoolRoot.get("schoolName"),p));

java - 获取多个 onetoMany 关系 Hibernate JPA

我正在使用HibernateJPA1.0。我有以下类型的模型,我认为manyToOne和oneToOne关系是“急切地”获取的,oneToMany是“懒惰地”获取的。我想获取实体A及其所有关联,其中a.id=?A一对多BB一对一C单对多BoneToOneEEoneToManyDBoneToOneFFoneToManyD是否可以在单个查询中加载该实体?或者在不考虑“n+1选择问题”的查询子集中!到目前为止,我加载所有A关联的解决方案是执行以下操作:“从A中选择DISTINCTaJOINFETCHa.bsWHEREa.id=:aID”然后使用代码迭代以获取所有其他关联。集合Bbs=A.ge

java - Hibernate (JPA) 多个@OneToMany 用于同一模型

我有两个模型。@EntitypublicclassStudent{@Id@GeneratedValue(strategy=GenerationType.AUTO)protectedlongid;@?protectedAddresshomeAddress;@?protectedAddressschoolAddress;}@EntitypublicclassAddress{@Id@GeneratedValue(strategy=GenerationType.AUTO)protectedlongid;@?protectedListstudents;}我需要在homeAddress、schoo