Questions tagged [one-to-one]

Refers to the quantity of an entity as a relationship to another entity. Meaning that for every instance of an entity, there is a single related instance of another entity.

Refers to the quantity of an entity as a relationship to another entity.

Meaning that for every instance of an entity, there is a single related instance of another entity.

1496 questions
18
votes
3 answers

(1+N) selects with OnetoOne associations

Considering the following model: @Entity public class User { @Id @Column(name = "USER_ID") private Long userId; @Column(name = "FIRST_NAME") private String firstName; @Column(name = "LAST_NAME") private String…
David
  • 910
  • 1
  • 12
  • 22
18
votes
5 answers

Optional one-to-one mapping in Hibernate

How do I create an optional one-to-one mapping in the hibernate hbm file? For example, suppose that I have a User and a last_visited_page table. The user may or may not have a last_visited page. Here is my current one-to-one mapping in the hbm…
hibernate
  • 737
  • 2
  • 7
  • 7
17
votes
2 answers

AspNetUsers' ID as Foreign key in separate table, one-to-one relationship

I have looked up and down, tried all the different and various ways of being able to store a foreign key of the AspNetUser table in a separate Customer table. I'm still new at ASP.NET and the Entity Framework, but I've read quite a few posts and…
JayEz
  • 173
  • 1
  • 1
  • 6
16
votes
1 answer

Hibernate one-to-one, No row with the given identifier exists exception

I need a link between two entities, so I use a one-to-one @Entity @Table(name = "T_USER") public class User implements Serializable { @Id @Column(name = "user_id") private int userId; @Column(name = "login") private String…
BasicCoder
  • 1,661
  • 10
  • 27
  • 42
15
votes
4 answers

Hibernate not caching my OneToOne relationship on the inverse side

I have code like: @Entity @Table(name = "A") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class A { @OneToOne(cascade={CascadeType.ALL}, fetch=FetchType.EAGER, mappedBy="a") public B getB() {}; } @Entity @Table(name =…
Dainius
  • 1,765
  • 1
  • 17
  • 36
14
votes
3 answers

JPA / Hibernate unidirectional one-to-one mapping with shared primary key

I'm having a very hard time trying to get a unidirectional one-to-one relationship to work with JPA (Provider: Hibernate). In my opinion this should not be too much of a hassle but apparently JPA / Hibernate disagrees on that ;-) The problem is that…
Korgen
  • 5,191
  • 1
  • 29
  • 43
14
votes
2 answers

SQLAlchemy query filter on child attribute

My model consists of a Parent and Child with a one-to-one relationship: class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) name = Column(String) child = relationship("Child", backref="parent",…
kostia
  • 305
  • 1
  • 3
  • 8
14
votes
1 answer

SQLAlchemy one-to-one relation, primary as foreign key

I am mapping classes to existed MySQL tables generated by Drupal. I need to relate to tables(one-to-one), but I've got a problem. Two tables have the column nid. Both fields are primary keys. I can not define foreign key without a primary key. And…
Victor Shelepen
  • 1,966
  • 2
  • 16
  • 41
14
votes
3 answers

Hibernate - bidirectional @OneToOne

I have 2 classes: User and UserPicture which have a 1:1 relationship. public class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id", nullable = false, unique = true) private int id; private String…
user1731299
  • 567
  • 3
  • 10
  • 24
13
votes
6 answers

store many of relation 1:1 between various type of objects : decoupling & high performance

I have 300+ classes. They are related in some ways. For simplicity, all relation are 1:1. Here is a sample diagram. (In real case, there are around 50 relation-pairs.) Note: For some instances, some relation may not exist. For example, some…
javaLover
  • 6,347
  • 2
  • 22
  • 67
13
votes
3 answers

When to use one-to-one relationships in Django models?

I've read a few places (see the second answer) that one-to-one relationships in Django models should almost always only be used for inheritance, or to access an otherwise inaccessible model (like the Django user model). However, it seems like…
ekrah
  • 584
  • 1
  • 5
  • 17
13
votes
3 answers

Rails one-to-one relationship

I have the following: class User < ActiveRecord::Base has_one :car, :class_name => 'Car', :foreign_key => 'user_id' class Car < ActiveRecord::Base belongs_to :worker, :class_name => 'User', :foreign_key => 'user_id' It is basically a…
cgf
  • 3,369
  • 7
  • 45
  • 65
12
votes
2 answers

@OneToOne unidirectional and bidirectional

I have two examples that first is @OneToOne unidirectional mapping and second bidirectional. In unidirectional mapping, the owning-side table must contain a join column that refers to the other table's id; then in bidirectional both of them must…
Rahman Usta
  • 716
  • 3
  • 14
  • 28
12
votes
1 answer

Entity Framework saving data in one-to-one associations

I'm trying to use the foreign key association approach to achieve a one-to-one association in EF. In my case there's an association between a User and a Team, and I need a navigation property in each of them. I bumped into a problem when trying to…
12
votes
4 answers

How to declare one to one relationship using Entity Framework 4 Code First (POCO)

How to declare a one to one relationship using Entity Framework 4 Code First (POCO)? I found this question (one-to-one relationships in Entity Framework 4) , but the article that the answer references was not useful (there is one line of code that…
Paul Hiles
  • 9,558
  • 7
  • 51
  • 76