one-to-many

How to define nested Identifying Relationships Entity Framework code first

馋奶兔 提交于 2019-11-30 14:53:05
I'm using EF5 code first in a simple test application at the moment to test various functions. I have defined an 'identifying relationship' between two entities which represent a one-to-many link. Here I define a PhotoCollection that has many child Photo entities; public class PhotoCollection { public int Id { get; set; } public virtual ISet<Photo> Photos { get; private set; } public PhotoCollection() { Photos = new HashSet<Photo>(); } } public class Photo { [Key, ForeignKey("Parent"), Column(Order = 1)] public int PhotoCollectionId { get; set; } [Key, Column(Order = 2)] public int PhotoId {

ids for this class must be manually assigned before calling save()

做~自己de王妃 提交于 2019-11-30 14:21:04
I've got some problem with hibernate @OneToMany mapping. It goes like here @Entity @Table(name = "albums") @SequenceGenerator(name = "ALBUMS_SEQ", sequenceName = "albums_seq", allocationSize = 1) public class AlbumDs { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ALBUMS_SEQ") private Integer id; private Integer ownerId; private String name; private String description; private Date created; @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "albumId", insertable = true, updatable = true) private Set<UserAlbumDs> users = new HashSet<UserAlbumDs>(); public Integer

Hibernate insert cascade not inserting foreign key

时间秒杀一切 提交于 2019-11-30 13:47:17
I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @OneToMany(fetch=FetchType.LAZY, mappedBy="file", cascade=CascadeType.ALL) private List<Tag> tags; ....... OTHER PROPERTIES ....... @Entity public class Tag ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @ManyToOne @JoinColumn(name="file_id") private File file; @Column private String tag; ....... OTHER PROPERTIES ....... I am trying to insert into File (and subsequently Tag) by doing the following: File file = new File(); Tag tag = new Tag(); tag

OneToMany - what are the differences between join table and foreign key?

风格不统一 提交于 2019-11-30 13:06:23
There is the possibility to disable the @OneToMany relationship join table with the @JoinColumn annotation. The default is a join table. What are the advantages and disadvantages for a production system for example? When should I use a join table and when not? Thank you. By default @OneToMany will create a join table only if you'll use unidirectional relationship . In other words, if you have Employee and Project entities and the Employee entity is defined as follows (assume there is no orm.xml entries for these entities) : @Entity public class Employee { // ... @OneToMany Set<Project>

OneToMany relationship is not working

余生长醉 提交于 2019-11-30 12:15:47
问题 My Tables: Product : id, name Offer : id, value, product_id Entities: @Entity @Table(name="product") public class Product implements Serializable { @OneToMany(mappedBy="product") private Set<Offer> offers; ... } @Entity @Table(name="offer") public class Offer implements Serializable { @ManyToOne @JoinColumn(name="PRODUCT_ID") private Product product; ... } When I try to get some data from table Product , I get a java.lang.NullPointerException , and this code: product.getOffers() returns:

Programming a one-to-many relationship

落花浮王杯 提交于 2019-11-30 11:52:49
问题 So I am surprised that doing a search on google and stackoverflow doesn't return more results. In OO programming (I'm using java), how do you correctly implement a one-to-many relationship? I have a class Customer and class Job . My application is for a fictious company that completes jobs for customers. My current implementation is so that the Job class doesn't have anything to do with the Customer class, there is no reference to it at all. The Customer class uses a collection and methods to

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

拈花ヽ惹草 提交于 2019-11-30 09:08:07
问题 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>

Hibernate Unidirectional Parent/Child relationship - delete() performs update on child table instead of delete

自古美人都是妖i 提交于 2019-11-30 07:12:22
问题 If I delete a record from the Parent table I want the corresponding records in the child table to be deleted. How can I make Hibernate delete from the Child table rather than attempt to update with a null? I'm using Hibernate 3 but cannot use annotations at this time. I've attached copies of HBM, DAO etc below. -- Thank you in Advance When attempting to delete data from tables in Parent/Child relationship I get the following error: Testcase: testDelete(com.dressbarn.imbo.model.data.hibernate

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

坚强是说给别人听的谎言 提交于 2019-11-30 05:01:08
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 this example, the annotation for street is not used on validation. class Person { ... /** * @ORM

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

試著忘記壹切 提交于 2019-11-30 04:53:16
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 various different annotation configurations with no luck. Is what I'm asking for possible? Database GLOBAL