one-to-many

one to many mapping to a property of superclass

大兔子大兔子 提交于 2019-12-08 15:44:25
问题 I have a superclass Questions and its subclass MultipleChoiceQuestions Superclass has a field activity I want to create a Set<MultipleChoiceQuestions> and use OneToMany annotation using mappedBy = "activity" e.g. @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" ) private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>(); I am getting this error: org.hibernate.AnnotationException: mappedBy reference an unknown target

Updating oneToMany entity sets parent to null

假如想象 提交于 2019-12-08 13:00:27
问题 I have a list of Role entities on a User entity linked with a @OneToMany relationship. When I change the list on the User entity, i.e change the roles, hibernate removes the old roles and adds the new ones as desired. However the foreign key field is set to null on the Role entity. Can you explian why the foregign key field is null, and how would I change it so it gets picked up on an update? User.java @SerializedName("userrole") @Expose @OneToMany(mappedBy = "user", fetch = FetchType.EAGER,

SQLite UPDATE field in one table based on foreign key of another table

与世无争的帅哥 提交于 2019-12-08 12:32:53
问题 As in this question (SQLite field with a list of foreign keys), I'm trying to keep my real estate agents and listings in an SQLite DB with python. I did as suggested and now have tables that look like this: CREATE TABLE listings( listing_id INTEGER PRIMARY KEY AUTOINCREMENT, listing_address TEXT UNIQUE NOT NULL, acq_date DATE agent_id INTEGER, FOREIGN KEY (agent_id) REFERENCES agent (agent_id) ) CREATE TABLE agent( agent_id INTEGER PRIMARY KEY AUTOINCREMENT, agent_name TEXT NOT NULL, agent

How to Map many one-to-many relationship in ASP.NET MVC?

白昼怎懂夜的黑 提交于 2019-12-08 12:04:20
问题 I have few Domain Models - Address , Customer , Employee , StoreLocation . Address has many to one relationship with Customer and Employee and one to one relationship with StoreLocation. public class Address { public int Id; public string Line1 { get; set; } public string Line2 { get; set; } public string Line3 { get; set; } } public class Customer { public int Id { get; set; } public string Name { get; set; } public IList<Address> Addresses { get; set; } } public class StoreLocation { public

Why to have a join table for 1:m relation in SQL

感情迁移 提交于 2019-12-08 09:54:25
问题 What is the benefit of having junction tables between the first 1:m and the second 1:m relations in the following database? alt text http://dl.getdropbox.com/u/175564/db/db-simple.png The book Joe Celko's trees and hierarchies in SQL for Smarties says that the reason is to have unique relations in 1:m's. For instance, the following tables resrict users to ask the exactly same question twice and to give exactly the same answer twice, respectively. The first 1:m relation users-questions =======

SQLite field with a list of foreign keys

心不动则不痛 提交于 2019-12-08 09:32:54
问题 I am building an SQLite DB to keep my real estate agents' listings. I have been able to use a foreign key to identify a listing for each agent, but I want to make a list of listings in each agent's record; moving from a one-to-one relationship between agents and listings to a one-to-many relationship. Looking here: http://www.sqlite.org/draft/foreignkeys.html , there is no mention of a field that is a 'list of foreign keys'. Is what I'm trying doable? I considered that, as a workaround, I

Spring Data JPA. Pagination for child entities

孤者浪人 提交于 2019-12-08 06:09:44
问题 I'm using Spring Data JPA with Spring boot version 1.3.6.RELEASE with in-memory database. I'm wondering how to paginate the child entities from a parent entity. Setting fetch to LAZY is not a solution for me. Here is the use case : Parent has an unidirectional oneToMany relation with Child entity . The number of Child for one Parent can reach 100,000 (LAZY is not a solution) I don't want to fetch all the child to do the pagination (For CPU and Memory reason) Here is a code sample : @Entity

NHibernate composite id mapping issue, bi/uni-directional OneToMany, ManyToOne and ManyToMany

谁说胖子不能爱 提交于 2019-12-08 05:13:55
问题 In my project all of entities have composite primary keys [systemId as long, deviceId as long, id as long]. Values filled manualy before I save the entity. I'm using "code first" approach and to provide simplicity references NHibernate.Mapping.Attributes extension to define schema with attributes just like in Java based Hibernate. All entities have an abstract base type which provides shared properties and functionality: [Serializable] public abstract class EntityBase { [CompositeId(0, Name =

SubSonic 3 - Simple repository - One to many relations

别来无恙 提交于 2019-12-08 04:55:00
问题 It's the first time I use Subsonic. Let say I have those classes : public class Store { public int Id { get; set; } public String Name { get; set; } } public class Employee { public int Id { get; set; } public String Name { get; set; } } An employee is related to a store with is hired date. This means that in the database I will have a middle table With StoreId, EmployeeId, StartDate, EndDate UPDATE An employee can work to the StoreA from 2009-01-01 to 2009-04-04 and work for StoreB from 2009

mySQL: Querying one-to-many -table?

社会主义新天地 提交于 2019-12-08 04:42:52
问题 What would be the appropriate way to query products with a specific property in the following database design with a one-to-many approach? I guess that I should be doing something like the following: SELECT (*) FROM productProperties WHERE property = 'weight' AND value = '10' But what if I need to products that has both weight = 10 & color = blue in the same query? Example of database design: table: products ------------------------ id | name | price ------------------------ 0 | myName | 100