one-to-many

JPA Hibernate collections not lazily loaded

流过昼夜 提交于 2019-11-28 06:39:17
问题 I have a JPA setup in such a way that if I do not use lazy load, almost the entire database will be loaded. I also use serializing directly on the models so sometimes I need to initialize the proxies. I only want to use lazy load on the collections. The fact that some singular entities are fetched eagerly works just fine. But no matter how I try to setup the collections I never get a collection of proxies, I always get the fully loaded collection. This is some example code: @Entity public

Hibernate @OneToMany with mappedBy (parent-child) relationship and cache problem

拟墨画扇 提交于 2019-11-28 06:36:59
I have this problem for a long time now, I have searched the web and SO in and out and didn't find a solution yet. I hope you can help me on that. I have a parent-child relationship between two entities like the following: @Entity public class Parent { // ... @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) private Set<Child> children = new HashSet<Child>(); // ... } @Entity public class Child { // ... @ManyToOne(fetch = FetchType.LAZY) private Parent parent; // ... } The thing is that when I create a new child and assign it to a parent, the parent doesn't

@OneToMany without inverse relationship and without a join table?

一笑奈何 提交于 2019-11-28 05:17:36
This is a similar problem to "Hibernate @OneToMany without a separate join table" , in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to result in a join table being automatically generated... is there a workaround for this? Arthur Ronald In JPA 2.0+ you can use @JoinColumn as a way to avoid to generate joined table. Try it. @OneToMany @JoinColumn(name="COLUMN_NAME") UPDATE The info provided above has been extracted from EJB 3.0 o'reilly book (Look for The @JoinColumn annotation

Hibernate @EmbeddedId + join

 ̄綄美尐妖づ 提交于 2019-11-28 05:13:45
问题 i have a hibernate mapping problem. I have the following two DB tables (I don't allowed to change the DB): LOCATIONS { ID, -- PK NAME } LOCATION_GROUPS { LOC_ID, -- PK, and FK to LOCATIONS.ID GROUP_NAME -- PK } I tried to create entities for these DB tables, but i don't know how to map the connection between the tables. Here is my attempt (but it's wrong): @Embeddable public class LocationGroupId implements Serializable { private static final long serialVersionUID = -6437671620548733621L;

JPA @OneToMany -> Parent - Child Reference (Foreign Key)

怎甘沉沦 提交于 2019-11-28 04:06:22
i have a Question about referencing ParentEntities from Child Entites ir If i have something like this: Parent.java: @Entity(name ="Parent") public class Parent { @Id @Generate..... @Column private int id; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent") private Set<Child> children; simple ... getter and setter ... } And the Child.java: @Entity(name ="Child") public class Child{ @Id @Generate.... @Column private int id; @ManyToOne private Parent parent; ... simple getter an setter } Following Tables are going to be created: Parent: int id Child: int id int

One to many association - Join tables with non primary key column in JPA

时光总嘲笑我的痴心妄想 提交于 2019-11-28 03:33:34
问题 I'm working on legacy system, need to read some of the info from database. Below are the table relationship Vendor (vendorId - pk, vendorEid, name) VendorContactBridge (bridgeId -pk, vendorEid, contactEid) Contact (contactId -pk, contactEid, phone) vendorEid and contactEid are not the primary key of the table but used as join column in Join table VendorContactBridge. Vendor Entity - @Entity @Table(name="Vendor") public class Vendor implements Serializable{ @Id @Column(name="VENDORID") private

Value object or entity object in my Hibernate mapping?

Deadly 提交于 2019-11-28 01:47:33
问题 I'm trying to design a pretty simple app and am getting myself a bit confused with Hibernate's definition of entity and value objects (as defined in Chapter 4 of Java Persistence with Hibernate). What I have is an app with customers, who can place orders (one to many relationship). Each of these orders has many order lines (also one to many). Now, I think that customers have identity (customer number) and so do orders (order numbers) so they are therefore entity objects? My confusion comes in

symfony easyadmin one to many form

我们两清 提交于 2019-11-28 01:19:30
问题 i am new to the easyadmin bundle and i am looking if it is possible to add childs directly from the parent object So i got 3 objects : - Recipe namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Recipe * * @ORM\Table(name="recipe") * @ORM\Entity(repositoryClass="AppBundle\Repository\RecipeRepository") */ class Recipe { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column

Using both many-to-many and one-to-many to same entity

好久不见. 提交于 2019-11-28 00:59:07
问题 I have a many-to-many association in EF Code-First (as explained in this question), and I want to use a one-to-many to the same entity as well. The problem is EF does not produce the right database scheme. Code: public class A { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<B> ObjectsOfB { get; set; } } public class B { public int Id { get; set; } public virtual A ObjectA { get; set; } public virtual ICollection<A> OtherObjectsOfA { get; set; } } When

Android: SQLite one-to-many design

自闭症网瘾萝莉.ら 提交于 2019-11-27 20:25:53
问题 Anyone has good advise on how to implement one-to-many mapping for SQLite using ContentProvider ? If you look at Uri ContentProvider#insert(Uri, ContentValues) you can see that it has ContentValues param that contains data to insert. The problem is that in its current implementation ContentValues does not support put(String, Object) method and class is final so I cannot extend it. Why it is a problem? Here comes my design: I have 2 tables which are in one-to-many relationship. To represent