I'm a novice in JPA please stay with me. Apparently there is no question about how to create a composite primary key from foreign keys in a property access way. Question If I use the property access type as in the example below, do I have to define getters and setters for the referenced FKs as well ? I did not think that that's the case but the official documentation of Java EE6 d
我是JPA的新手,请留在我身边。 显然,如何以属性访问方式从外键创建组合主键是没有问题的。 题 如果我按照下面的示例使用属性访问类型,那么是否还必须为引用的FK定义getter和setters? 我不认为这是事实,但Java EE6的官方文档是这样做的。 适用于J2EE的Oracle®容器Enterprise JavaBeans开发人员指南 复合主键类具有以下特征: 这是一个POJO课程。 它必须是公开的,并且必须有一个公共的无参数构造函数。 如
What is the difference between: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY) @JoinColumn(name = "companyIdRef", referencedColumnName = "companyId") private List<Branch> branches; ... } and @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY, mappedBy = "companyIdRef") priva
有什么区别: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY) @JoinColumn(name = "companyIdRef", referencedColumnName = "companyId") private List<Branch> branches; ... } 和 @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY, mappedBy = "companyIdRef") private List<Branch>
I understand that JPA 2 is a specification and Hibernate is a tool for ORM. Also, I understand that Hibernate has more features than JPA 2. But from a practical point of view, what really is the difference? I have experience using iBatis and now I'm trying to learn either Hibernate or JPA2. I picked up Pro JPA2 book and it keeps referring to "JPA provider". For example: If yo
我知道JPA 2是一个规范,Hibernate是一个ORM的工具。 另外,我明白Hibernate比JPA 2具有更多的功能。但从实际角度来看,真正的区别是什么? 我有使用iBatis的经验,现在我正在尝试学习Hibernate或JPA2。 我拿起了Pro JPA2书,它一直提到“JPA provider”。 例如: 如果您认为某项功能应该标准化,您应该向JPA提供商说出要求并提出要求 这使我困惑,所以我有几个问题: 通过单独使用JPA2,我可以通过简单地注释我的POJO
In our application, we need to have fields that are assignable only once. At first we thought of encapsulating the fields and making the setters private. However, some questions arouse: Without a public setter, is Hibernate still able to map the field from the database? Can I strip out the setter and make the field mutable only in the entity constructor? Finally, is there any standard JP
在我们的应用程序中,我们需要有只能分配一次的字段。 起初,我们想到封装领域并使制定者保密。 但是,一些问题引起了: 如果没有公共setter,Hibernate是否仍然能够映射数据库中的字段? 我可以去掉setter并只在实体构造函数中使字段可变吗? 最后,有没有标准的JPA方法可以使字段不可变? 提前致谢。 广告。 1:如果注释放在字段而不是getter上,我相信JPA使用纯专用字段进行读写。 最近我发现Hibernate作为底
I have Hibernate Entities that look something like this (getters and setters left out): @Entity public class EntityA { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") private EntityB parent; } @Entity public class EntityB extends SuperEntity { @OneToMany(mappedBy = "parent") @Fetch(FetchMode.SUBSELECT) @JoinColumn(name = "parent_id") private Set<
我有Hibernate Entities,看起来像这样(getters和setters被忽略): @Entity public class EntityA { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") private EntityB parent; } @Entity public class EntityB extends SuperEntity { @OneToMany(mappedBy = "parent") @Fetch(FetchMode.SUBSELECT) @JoinColumn(name = "parent_id") private Set<EntityA> children;
Im trying to sum value's on simular tables from multiple child classes using Hibernate Inheritance. Using "@Inheritance(strategy = InheritanceType.JOINED)" on my parent class, and have multiple subclasses extending this. My problem is when I use Criteria with "Projections.sum" to get a result, Hibernate does a funny join. Its as if hibernate takes the first matching r
我试图使用Hibernate Inheritance在来自多个子类的同类表上对值进行求和。 在我的父类上使用“@Inheritance(strategy = InheritanceType.JOINED)”,并有多个子类来扩展它。 我的问题是,当我使用Criteria和“Projections.sum”来获得结果时,Hibernate做了一个有趣的连接。 它就好像hibernate采用第一个匹配结果并对它进行求和 - 忽略其余部分,我甚至不知道这是否可以完成。 希望我的代码能够澄清我的问题。 动物 - 父
I'm using JPA over Hibernate in my web-app. Here are two entities (only getters are shown): class Child { private Parent parent; @ManyToOne(optional=false) @JoinColumn(name="parent_id", referencedColumnName="parent_id", nullable=false, updatable=false) public Parent getParent() { return parent; } } class Parent { private Collection children; @OneToMany(fetch=FetchTyp
我在我的Web应用程序中使用JPA而不是Hibernate。 这里有两个实体(只显示获取者): class Child { private Parent parent; @ManyToOne(optional=false) @JoinColumn(name="parent_id", referencedColumnName="parent_id", nullable=false, updatable=false) public Parent getParent() { return parent; } } class Parent { private Collection children; @OneToMany(fetch=FetchType.EAGER, mappedBy
I am using Hibernate 4.3.8 as ORM tool for our MySql database. I have a class to be mapped which is annotated as follows: @Entity @DynamicUpdate @Table(name = "myclass") public class MyClass { @Id @Column(name = "myClassId") private String id; @Column(name = "status") private String status; @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "myclas
我使用Hibernate 4.3.8作为我们MySql数据库的ORM工具。 我有一个类被映射,它被注释如下: @Entity @DynamicUpdate @Table(name = "myclass") public class MyClass { @Id @Column(name = "myClassId") private String id; @Column(name = "status") private String status; @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "myclass_children", joinColumns = @JoinColum
So I have a Hibernate entity(lets call it Zoos) with a many-to-many relationship set up like this: @ManyToMany(cascade = {}) @JoinTable(name = "animal", joinColumns = @JoinColumn(name = "zoo_id"), inverseJoinColumns = @JoinColumn(name = "animal_id")) @LazyCollection(LazyCollectionOption.FALSE) public List<Animal> getAnimal() { return animals; } So now I want to find all zoos w
所以我有一个Hibernate实体(让我们称之为动物园),并设置了如下的多对多关系: @ManyToMany(cascade = {}) @JoinTable(name = "animal", joinColumns = @JoinColumn(name = "zoo_id"), inverseJoinColumns = @JoinColumn(name = "animal_id")) @LazyCollection(LazyCollectionOption.FALSE) public List<Animal> getAnimal() { return animals; } 所以现在我想找到动物“狮子”,“老虎”和“熊”的所有动物园。
There have been some discussions here about JPA entities and which hashCode() / equals() implementation should be used for JPA entity classes. Most (if not all) of them depend on Hibernate, but I'd like to discuss them JPA-implementation-neutrally (I am using EclipseLink, by the way). All possible implementations are having their own advantages and disadvantages regarding: hashCode() / e
这里有一些关于JPA实体的讨论,以及哪些hashCode() / equals()实现应该用于JPA实体类。 大多数(如果不是全部的话)都依赖于Hibernate,但我想讨论它们JPA-implementation-neutrally(顺便说一句,我使用EclipseLink)。 所有可能的实现都有自己的优点和缺点 : hashCode() / equals() )为List / Set操作提供合同一致性 (不变性) 是否可以检测到相同的对象(例如来自不同会话,来自延迟加载的数据结构的动态代理)