我有4个实体与OneToMany关联映射。实体A (OneToMany ) -> B (OneToMany ) -> C (OneToMany )-> D
我想立刻拯救整个建筑。所以我把cascade = CascadeType.ALL放在每个OneToMany上。但似乎JPA不想保存C和D关联,我所完成的只是引用A的B,而C和D是在没有引用的情况下保存的。
当我用引用(如c.setB(b)和d.setC(c) )保存它时,它会给出错误object references an unsaved transient instance - save the transient in
例如,让我定义以下实体:
@Entity
public class Box{
@ManyToOne
Apple apple;
@ManyToOne
Orange orange;
}
@Entity
public class Apple {
@OneToMany
List<Box> boxes;
@ManyToMany
List<Orange> OrangeBoxMates;
}
@Entity
public class Orange {
@OneToMany
List<
我想知道如果oneToMany关系更新,域名版本是否会改变。例如,存在与地址具有OneToMany关系的用户实体。那么,如果我更新地址列表,会对用户版本有影响吗?
@Entity public class User {
@Id @Column(name = "id")
@GeneratedValue
private Long id;
@OneToMany (mappedBy = "document")
public Set<Addresses> userAddresses;
@Versio
我在Postgres中使用TypeOrm。我有下面的实体(缩小)
class A {
@OneToMany()
b:B
@OneToMany()
c:C
}
class B {
@ManyToOne()
a: A
}
class C {
@OneToMany()
d: D
@OneToMany()
e: E
@ManyToOne()
a: A
}
class D {
@Ma
我正在尝试对一个业务实体进行建模,其中所述业务可以有几个父业务和几个子业务。我不确定哪种关系是合适的,甚至不知道什么映射是合适的。我熟悉SQL,但对Java中的ORM还不熟悉。
我的想法是,一家企业可以有很多孩子,也可以没有孩子,企业可以有很多父母,也可以没有父母。因此,我尝试既将OneToMany设置为OneToMany,又将其设置为OneToMany,这两种设置都会导致以下错误:Illegal use of mappedBy on both sides of the relationship.
实现:
@Entity
public class Business{
@Id
@
我有3节课:
class A {
// some variables...
// even some @OneToMany List<MyOtherObject> variables
}
class B {
@OneToMany
List<C> cList;
// other...
}
class C {
// some variables...
}
使用这种配置一切正常,但是:当我添加到类A:@OneToMany List<B>中时,spring中出现了一个关于类路径的错误(没有提到hibernate异常)。
简而言之:我想实现Lis
是否可以使用JPA或Hibernate注释显式指定要运行的查询以检索相关对象?
具体来说,我有以下实体:导师、学生以及导师与学生之间明确的OneToOne关系,教程:
@Entity
public class Student {
@OneToMany Collection<Tutorial> tutorials;
}
@Entity
public class Tutor {
@OneToMany Collection<Tutorial> tutorials;
}
@Entity
public class Tutorial {
@OneToOne Tuto
我正在使用Hibernate JPA1.0。
我有以下类型的模型,我认为manyToOne和oneToOne关系是“急切地”获取的,oneToMany是“惰性地”获取的。
我想获取实体A及其所有关联,在哪里a.id=?
A oneToMany B
B oneToOne C
C oneToMany D
- B oneToOne E
- E oneToMany D
- B oneToOne F
- F oneToMany D
是否可以在一个查询中加载该实体?或者在一个子集的查询中,记住"n+1选择问题“!
到目
我在通过OpenJPA实现使用JPA1.0时遇到了问题。我的数据模型包括一个与腿部有OneToMany关系的旅行和一个与乘客的OneToMany关系。在PassengerLeg中,腿和乘客是同一位置的。这被映射为双向OneToMany/ManyToOne。从本质上说,我的数据模型中有一颗钻石。如果一次旅行有2条腿和3名乘客,就会有6 passengerLegs。对于不同的用例,我需要每个实体的每个方向。现在,当我试图加载所有内容时,PassengerLeg中的leg字段将为null,我不知道原因。下面是我的课程的简略表示:
@Entity
public class Trip {
@One
我尝试将我的Department和Mandator类持久化到hsqhldb,但是它给出了这个错误。
Exception Description: [class ch.printsoft.mailhouse.usermgr.entity.Mandator] uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as target entity in the relationship attribute [field departments].
at org.eclipse.persistence.ex
我有一个设置为OneToMany ManyToOne OneToMany的标签系统,如下所示: 到标签的项目OneToMany TAGS ManyToOne to TAG ManyToOne ITEM TAG OneToMany to TAGS 此关系的项目表单字段是来自TAG的EntityType,因此我有一个数据库中可用标签的列表可供选择 当我保存我的表单时,我得到了Expected value of type "App\Entity\tags" for association field "App\Entity\Item#$tags", got "
在JPA中,我是否可以额外约束@OneToMany或@ManyToMany以生成等同于以下内容的内容:
select * from other_table a where a.fk_id = {id} and arbitrary other predicates
换句话说,我可以用下面的代码获取所有员工的电话:
@Entity
public class Employee {
@Id
@Column(name="EMP_ID")
private long id;
...
@OneToMany(mappedBy="owner")
priva
我正试图在我们的项目中建立我们的数据库。但是,当我尝试在@MappedSuperclass实体上使用@ManyToOne和@OneToMany时,会出现一些错误:
@MappedSuperclass
public abstract class Person extends Model{
//public abstract class Person {
// ATTRIBUTES
@Column(columnDefinition = "varchar(20) not null")
private String firstName;
@Column