entity-relationship

Can I set an entity relation with just the ID?

烈酒焚心 提交于 2019-12-07 03:16:43
问题 I have a JPA (Hibernate) entity: @Entity class Transaction { @ManyToOne private Room room; } When I create a new Transaction , I know the ID of the Room that it should refer to (but don't have a Room object). Can I somehow create and persist a Transaction with just this info, or do I really need to: Room room = em.find(roomId, Room.class); em.persist(new Transaction(room, ...)); 回答1: You can use EntityManager.getReference() to get a proxy of the related entity without accessing the database.

2 relationships between 2 entities in ER diagram

爷,独闯天下 提交于 2019-12-07 01:43:16
问题 I'm trying to draw an ER diagram describing the following: -"Department" employs "Employees" -Some "Employees" are "Special" and have more attributes -Some of the "Employees" ("Special" and non special) are "Managers" -"Managers" manage "Departments" So, to convey this I have: Department ------(employs)------- Employee-----<--------Special | | |-----------(manages)---------- From my understanding, I cannot have 2 relationships between 2 entities. How do I deal with this situation then? 回答1:

Database Design for a Multiplayer/Single Quiz game

家住魔仙堡 提交于 2019-12-07 01:07:44
问题 I saw a lot of questions here but no one fits with my problem. I'm trying to create an ER model scalable, and if I want to add more data don't break almost anything, so what I've trying to create is : There are 2 types of users, let's say Admin and Worker, and they have different roles. Admin can do a CRUD of questions, and also can create a room where the users can join to play together (this is just a name, something like Kahoot! does) but maybe is a good idea to create more attributes

How to know relations between tables

☆樱花仙子☆ 提交于 2019-12-06 16:54:18
问题 I have a database in MySQL created by someone. I don't have any documentation of the database. How can I know the relationship between the tables? Is there any query or a procedure to generate a report so that it's easy to find the relations? I can look into Schema information and manually figure it out, but it would be great if I could generate a relationship report. 回答1: The better way as programmatically speaking is gathering data from INFORMATION_SCHEMA.KEY_COLUMN_USAGE table as follows:

EF Code First Fluent API - Cascade Delete

那年仲夏 提交于 2019-12-06 15:35:04
I have two models: public class User { ..... public virtual UserProfile UserProfile { get; set;} } public class UserProfile { ..... public virtual User User { get; set;} } The User is the master table and the relation is one to one. One user has only one UserProfile. How can I define the relationship between User and UserProfile using EF CodeFirst Fluent API in such a way that when I delete one user from User table the user profile from Userprofile is also deleted? Use WillCascadeOnDelete modelBuilder.Entity<UserProfile>() .HasKey(c => c.Id) .HasRequired(c => c.User) .WithRequiredDependent(c =

Map a navigation property to a instance var as Foreign key

烈酒焚心 提交于 2019-12-06 13:46:12
I'm developing an Entity Framework Code First (v. 4.4.0.0) C# library with .Net Framework 4.0. I don't know how to set zero-to-one relationship. My model is the following: A Talk can be created by only one user ( StarterUserId ). A Talk can have only one recipient user ( RecepientUserId ) or only one group ( RecipientGroupId ). Note : That means that RecepientUserId is null if RecipientGroupId is not null; or RecepientUserId is not null if RecipientGroupId is null. A user can be a recipient of zero or n Talks , but a group can have zero or one Talk . This is Talk class: [DataContract] public

Entity Relations from freebase dump

落爺英雄遲暮 提交于 2019-12-06 13:44:46
问题 I want to dump all entity-name-pair with a relation. Example : subject predicate object <freebase/ns/g.11bc7__xnw> <freebase/ns/people.place_lived.location> <freebase/ns/m.02_286> . Freebase in above line refers to url of freebase website. I extracted all triplets which have mid in subject and object, then I took the predicate as the relation. For the above example my code will output something like this: entity pair : g.11bc7__xnw , m.02_286 relation : people.place_lived.location I have two

PHP-Doctrine2: Items - Shops - ItemsAtShops - how to conveniently implement using Doctrine2?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 13:32:15
Somehow I can't figure out how to implement the following relations using Doctrine 2 syntax: I have Items and Shops. Each item has different price and different quantity at each shop. So, I have Items table, Shops table and ItemsAtShops table. How do I reflect the last one in Doctrine? I guess I need to create ItemsAtShops entity, relates ManyToOne -> Items and ManyToOne -> Shops, right? But in this case... how do I conveniently fetch a list of Items at the specific Shops with their prices and quantities at given Shops? So, that all these can be conveniently iterated? I need to render a page

objectify-appengine - Embedded class - not a supported property type

此生再无相见时 提交于 2019-12-06 12:43:09
I am trying out the objectify(version 2.2.3) embedded classes example (wiki) on google app engine. I am getting this error: java.lang.IllegalArgumentException: one: com.mypkg.LevelOne is not a supported property type. at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:184) The code I have is the same as the one in Wiki. The section in the controller: EntityWithEmbedded ent = new EntityWithEmbedded(); ent.one = new LevelOne(); ent.one.foo = "Foo Value"; ent.one.two = new LevelTwo(); ent.one.two.bar = "Bar Value"; The EntityWithEmbedded class: import

How can i add extra column to third table in Entity Framework?

核能气质少年 提交于 2019-12-06 11:49:22
Assume i have two entities, User and Notification : public class User { [Key] public int UserId { get; set; } // other public properties // Navigation Properties public virtual ICollection<Notification> Notifications { get; set; } } public class Notification { [Key] public int NotificationId { get; set; } // other public properties // Navigation Properties public virtual ICollection<User> Users { get; set; } } I'm simply adding many-to-many Relationship like this: modelBuilder.Entity<User>() .HasMany(u => u.Notifications) .WithMany(t => t.Users) .Map(m => { m.ToTable("UserNotifications"); m