one-to-one

Trouble linking one-to-one models in DataMapper

北慕城南 提交于 2019-12-11 06:21:45
问题 Using PostgreSQL and DataMapper to build a Sinatra app, running into some problems with DataMapper (I'm very new to it, used to Rails/AR ). For every Account created, it can either be an Artist , Venue , or Fan . Only one, no combining. When the user signs up, I can create the Account instance fine, but I'm having trouble creating the account's has 1 Artist or Venue or Fan instance (for ease of conversation, we'll use Artist as the belonging model). Here's my current model declarations: class

Hibernate 4.2, bidirectional @OneToOne and @Id

佐手、 提交于 2019-12-11 03:41:27
问题 I'm trying to use a OneToOne relationship to add optional data ( ExtraData ) to a main class ( MainItem ). All instances of ExtraData should be linked to an instance of MainItem , but not all instances of MainItem need to have an instance of ExtraData . (I'm primarily interested in a unidirectional relationship, but it seems that I need a bidirectional relationship to be able to cascade the updates and deletions of MainItem to ExtraData .) I'm having trouble using @Id , @OneToOne and

OneToOne bidirectional mapping foreign key auto fill

泄露秘密 提交于 2019-12-11 03:34:47
问题 I have a relationship one-to-one between two tables, but the foreign key is on the one I don't need to map, the DBA did this in favor of future changes. Let's imagine we have User and Address, today every user has only one address, and it will be mapped this way, but DBA believe in the future it could be a one to many mapping, so the foreign key of user is on the address, but the application have instances of users, which is important to fetch address automatically. We did it right, as follow

Hibernate @OneToOne with Shared Primary Key(bidirectional). Dependent entity not persisted in DB.

百般思念 提交于 2019-12-10 23:15:45
问题 I have two entities PointOfInterest (referred as POI from here on) and its Address. I want to define a one to one bidirectional mapping with shared primary key between the two, with POI as owner entity. I am using postgreSQL DB, POI table has POIId as PK, generated by a sequence generator defined in DB. Address table has column POIId which is the PK of Address table and also a FK to POI table's POIId column, along with other columns of its own. **PointOfInterest.java** @Entity @Table(name = "

JPA @OneToOne select lists with N+1 queries

时间秒杀一切 提交于 2019-12-10 17:33:37
问题 I'm actually trying to use JPA @OneToOne annotation to link a Child entity to its Parent . It's working well, except the fact that when getting a list of Child s, the JPA engine (Hibernate in this case) make 1+n queries. Here is the log of the Hibernate queries : select child0_.id as id1_0_, child0_.parent as parent3_0_, child0_.value as value2_0_ from child child0_ select parent0_.id as id1_1_0_, parent0_.something as somethin2_1_0_ from parent parent0_ where parent0_.id=? select parent0_.id

Doctrine 2 one-to-one via composite key

狂风中的少年 提交于 2019-12-10 15:43:48
问题 I am trying to set up a relationship as shown below. Each car can have one review. A car has a primary key on 2 columns. Review is referenced back to the car via the composite primary key. Simple, in theory. class Car { /** * @ORM\Id * @ORM\Column(type="string") */ private $make; /** * @ORM\Id * @ORM\Column(type="string") */ private $model; /** * * @ORM\OneToOne(targetEntity="Review", mappedBy="car", cascade={"persist"}) */ private $review; } class Review { /** * @ORM\Id * @ORM\OneToOne

One to one relationship involving multiple tables

╄→гoц情女王★ 提交于 2019-12-10 12:03:33
问题 Say, I have 3 tables. User which contains basic info about the users. SectionA which contains more info about the user. SectionB which also contains more info about the user. There can only be one SectionA and SectionB data for each user. My idea was to create a table design like this: id name section_a_id section_b_id 1 matt 1 1 Problem is, section_a_id and section_b_id cannot be auto incremented since they are not primary keys. So I tried a different approach and decided that the id primary

Database: `One to One` vs `One to Many`

こ雲淡風輕ζ 提交于 2019-12-10 11:57:06
问题 Note: This is not an inventory controlling system. I am just trying to map which medication given to which patient. I am not considering how many medication packets etc. Just a single medication event I am having a sudden confusion with database relationships, even after working with them for years. Below is my situation. I have a table called patient where it will hold the information of patients. I have another table called medication where it will hold the medicines prescribed for patient

Map One-To-One Relationship Doesn't Allow Inserting

烂漫一生 提交于 2019-12-10 10:48:09
问题 I'm trying to setup a one-to-one mapping from my Users to the UserDetails table. Say I have the following tables in my database: Users: - UserID (PK, Identity) - UserName - Password UsersDetails: - UserID (PK, FK) - FirstName - LastName I have created the following poco classes: public class User { public virtual int UserID { get; set; } public virtual string UserName { get; set; } public virtual string Password { get; set; } public virtual UserDetails Details { get; set; } } public class

In SQL / MySQL, are there reasons not to put one-to-one relationship in the same table?

倖福魔咒の 提交于 2019-12-10 05:37:10
问题 One-to-one relationship could usually be stored in the same table. Are there reasons not to store them in the same table? 回答1: Number and type of columns. There is a limit on the size of the columns in a table. See here. There is a maximum of 8,060 bytes per row. Very large tables can also affect performance and can be difficult to optimize and index well. This is apart from keeping data the is conceptually different, apart from each other. For example, a country and currency have a 1 to 1