one-to-many

Android: SQLite one-to-many design

蓝咒 提交于 2019-11-28 18:56:51
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 these in code I have 2 model objects. 1st represents the main record and has a field that is a list of

Hibernate @OneToMany remove child from list when updating parent

假如想象 提交于 2019-11-28 16:42:25
I have the following entities: TEAM @Entity @Table public class Team { [..] private Set<UserTeamRole> userTeamRoles; /** * @return the userTeamRoles */ @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "team", fetch = FetchType.LAZY) public Set<UserTeamRole> getUserTeamRoles() { return userTeamRoles; } /** * @param userTeamRoles * the userTeamRoles to set */ public void setUserTeamRoles(Set<UserTeamRole> userTeamRoles) { this.userTeamRoles = userTeamRoles; } } and USER_TEAM_ROLE @Entity @Table(name = "user_team_role") public class UserTeamRole { @ManyToOne(cascade = CascadeType.MERGE, fetch

How to configure a One-to-Many relationship in EF

二次信任 提交于 2019-11-28 13:24:51
I have the following model public class PageConfig : Base { // Properties Etc.. public ICollection<Image> ScrollerImages { get; set; } } My approach is to bind using a junction table { PageConfigID, ImageID }. In my model binder i tried the following.. modelBuilder.Entity<PageConfig>() .HasMany(x => x.ScrollerImages) .WithMany() .Map(x => { x.ToTable("junc_PageConfigScrollerImages"); x.MapLeftKey("PageConfigID"); x.MapRightKey("ImageID"); }); Which results in a null collection of images. How can i bind these Images to the PageConfig model? EDIT Most of the problem was due to user error. jic

Both One-To-One and One-To-Many relationships in Entity Framework 5 Code First

醉酒当歌 提交于 2019-11-28 12:27:39
i tried the whole day to get this working. I learned a lot about EF's Fluent API (e.g. this is an excellent article), however i had no success. I have three Entities: public class Address { [Key] public virtual int AddressId { get; set; } public virtual string AddressString { get; set; } } public class User { [Key] public virtual int UserId { get; set; } public virtual ICollection<Address> Addresses { get; set; } } public class House { [Key] public virtual int HouseId { get; set; } public virtual Address Address { get; set; } } and tried all combinations of HasMany, HasOptional, WithOptional,

PHP/mySQL - how to fetch nested rows into multidimensinal array

余生长醉 提交于 2019-11-28 11:37:32
Coming from another question of mine where I learnt not to EVER use db queries within loops I consequently have to learn how to fetch all the data in a convenient way before I loop through it. Let's say I have two tables 'scales' and 'items'. Each item in items belongs to one scale in scales and is linked with a foreign key (scaleID). I want to fetch all that data into an array structure in one query such that the first dimension are all the scales with all the columns and nested within, all items of one scale all columns. Result would be something like that: scale 1, scaleParam1, scaleParam2,

Select rows from one table, join most recent row from other table with one-to-many relationship

拥有回忆 提交于 2019-11-28 11:06:49
问题 What I would like to do is select a specific set of rows from one table (table A) and join with another table (table B), such that only one record will appear from table A, joined with the most recent record from table B, based on a datetime column. For example, table A has this structure (heavily simplified): id | col_1 | col_2 ---+-----------+---------------- 1 | something | something else 2 | val_1 | val_2 3 | stuff | ting 4 | goats | sheep And table B looks like this: id | fk_A | datetime

Hibernate relation OneToMany with non unique key

江枫思渺然 提交于 2019-11-28 11:02:13
问题 I am not able to describe my problem, I try it again with example: I have two entities (tables): Department and Person . Both tables have a field CODE which is not unique . How can I define manyToMany bidirectional relations between these tables? Departmen has collection Persons which returns all entities with Person.CODE eq Department.CODE Partner has collection Departments which returns all entities with Department.CODE eq Partner.CODE I need the relation definition - no sql or hpql query.

Construct JPA query for a OneToMany relation

╄→гoц情女王★ 提交于 2019-11-28 10:14:28
I've those 2 entities Class A { @OneToMany(mappedBy="a") private List<B> bs; } Class B { @ManyToOne private A a; private String name; } 1) I would like to construct a query that says get all A's that have at least one B with name ="mohamede1945" 2) I would like to construct a query that says get all A's that don't have any B with name = "mohamede1945" Could anyone help me? You can use the ANY and ALL constructs to filter the subquery. So something like 1. FROM A aEntity WHERE 'mohamede1945' = ANY (SELECT bEntity.name FROM aEntity.bs bEntity) 2. FROM A aEntity WHERE 'mohamede1945' <> ALL

Hibernate Many to one updating foreign key to null

淺唱寂寞╮ 提交于 2019-11-28 09:32:55
I am trying to get my @OneToMany and @ManyToOne relationships correct. Class 1: @Entity public class IdeaProfile { @Id @GeneratedValue private int ideaProfileId; private String name; Date dateConcieved; @OneToOne @JoinColumn(name="statusCode") private Status status; @OneToMany(fetch=FetchType.EAGER, targetEntity=Pitch.class, cascade=CascadeType.ALL) @JoinColumn(name = "ideaProfileId") private List<Pitch> pitchs; ....getters and setters.... Class2: @Entity public class Pitch { @Id @GeneratedValue private int id; @ManyToOne @JoinColumn(name = "ideaProfileId") private IdeaProfile ideaProfile;

SUBQUERY in NSPredicate and NSInvalidArgumentException

喜欢而已 提交于 2019-11-28 08:17:52
问题 I set up the following model in Core Data. Book has a to-many relationship, called toBookOrders, with OrderBook entity. The inverse is called toBook. Book has a BOOL value property called isSync. I set up the following NSPredicate . NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"Book" inManagedObjectContext:moc]; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF)"]; Through this predicate I