one-to-many

What's the lazy strategy and how does it work?

折月煮酒 提交于 2019-11-29 12:17:33
I have a problem. I'm learning JPA. I'm using embedded OpenEJB container in unit tests, but only working is @OneToMany(fetch=EAGER) . Otherwise is the collection allways null. I haven't found, how the lazy strategy works, how the container fills the data and in which circumstances triggers the container the loading action? I have read, that the action triggers when the getter is being called. But when I have the code: @OneToMany(fetch = LAZY, mappedBy="someField") private Set<AnotherEntities> entities = new Set<AnotherEntities>(); ... public Set<AnotherEntities> getEntities() { return entities

Entity Framework One-to-Many with Default

不羁的心 提交于 2019-11-29 12:13:38
I'm trying to do a one-to-many relationship in Entity Framework where one of the many items is optionally designated as default. public class SomeEntity { public int Id { get; set; } public Item DefaultItem { get; set; } // Optional public ICollection<Item> Items { get; set; } } public class Item { public int Id { get; set; } public string ItemName { get; set; } public SomeEntity SomeEntity { get; set; } } The configuration for the one-to-many in fluent API seems pretty straightforward: HasMany(e => e.Items).WithRequired(i => i.SomeEntity).WillCascadeOnDelete(true); But the solution for

JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of

为君一笑 提交于 2019-11-29 09:46:49
I have a composite key ContractServiceLocationPK made out of three id's ( contractId , locationId , serviceId ) of type long in an embeddable class. The class which uses this composite key, ContractServiceLocation , maps these ids, using @MapsId annotation, to their objects. Here's how it looks like (removed setters/getters and irrelevant properties): Contract @Entity @Table(name = "Contract") public class Contract implements Serializable { public Contract() { } @Id @GeneratedValue private long id; @OneToMany(mappedBy = "contract", cascade = CascadeType.ALL, fetch= FetchType.EAGER) Collection

Value object or entity object in my Hibernate mapping?

不打扰是莪最后的温柔 提交于 2019-11-29 08:02:18
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 with the order lines. An order line has quantity, product number and price. An order line can't exist

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

泪湿孤枕 提交于 2019-11-29 07:21:44
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 I remove the ObjectA property of class B the many-to-many association is generated correctly. When

Hibernate Many-To-One Relationship without Primary Key or Join Table

北慕城南 提交于 2019-11-29 02:55:13
问题 Problem I would like to start by saying that I realize the database structure is atrocious, but I cannot change it at this point in time. That being said, I have the need to create a one-to-many, bi-directional relationship in Hibernate (4.2.1) which involves no primary keys (only a unique key on the "parent" side of the relationship) and no join tables. The foreign key representing this relationship is a backpointer from the "child" to the "parent" (see below). I have searched and tried

Fluent nHibernate: one-to-many relationship Issue

好久不见. 提交于 2019-11-29 02:41:51
I have a problem with one-to-many relationships. I have the following domain classes: public class Installation : Entity<Installation> { public virtual string Name { get; set; } public virtual IList<Institution> Institutions { get; set; } public Installation() { Institutions = new List<Institution>(); } } public class Institution : Entity { public virtual string Name { get; set; } public virtual string Address { get; set; } public virtual string City { get; set; } public virtual Installation Installation { get; set; } } I have made the Entity base class according to the following post . I have

Symfony2+Doctrine - Validating one-to-many collection of entities

微笑、不失礼 提交于 2019-11-29 02:39:27
问题 I have a form to create a new entity. That entity has a collection of other entities that are also entered in that form. I want to use the validation options of the entity in the collection to validate those entities but it does not work. The validation rules of the "main" entity (Person) are checked, but the validation rules of the entities in the addressList collection (Address) are not checked. When I input invalid information in the fields, the submitted form is successfully validated. In

JPA / Hibernate OneToMany Mapping, using a composite PrimaryKey

只谈情不闲聊 提交于 2019-11-29 01:22:54
问题 I'm currently struggling with the right mapping annotations for a scenario using a composite Primary Key Class. First, what I am trying to achieve in words: I have 2 classes: group and FieldAccessRule. A Group can have many FieldAccessRules, while a FieldAccessRule only has ONE Group assigned. Modling this is not a problem so far (simplified): public class Group{ ... @OneToMany(mappedBy = "group") private Set<FieldAccessRule> fieldAccessRules; ... } and for the FieldAccessRule: public class

Constraint violation in Hibernate unidirectional OneToMany mapping with JoinTable and OrderColumn when removing elements

眉间皱痕 提交于 2019-11-29 01:04:02
问题 I have a problem when removing elements from a list mapped as described above. Here is the mapping: @Entity @Table( name = "foo") class Foo { private List bars; @OneToMany @OrderColumn( name = "order_index" ) @JoinTable( name = "foo_bar_map", joinColumns = @JoinColumn( name = "foo_id" ), inverseJoinColumns = @JoinColumn( name = "bar_id" ) ) @Fetch( FetchMode.SUBSELECT ) public List getBars() { return bars; } } Inserting Bar-instances and saving the Foo works fine, but when I remove an element