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
8
votes
2 answers

Hibernate OneToONe Lazy Fetching

I know this question was asked several times but I couldn't find a clear example and answer about this topic(I also tried other possible solutions). I am using Spring JPA and Hibernate and trying to make a lazy fetch for a OneToONe relation. I have…
8
votes
2 answers

How to get the associated data of `OneToOneField()` in Django?

I'm working in Django 2.0 I have a model Note to save note and two another models to add color labels to the note. class Note(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=250,…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
8
votes
3 answers

JPA @OneToOne select lists with N+1 queries

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 Childs, the JPA engine (Hibernate in this case) make 1+n queries. Here is the log of the…
8
votes
4 answers

Deleting from table with @OneToOne annotation

I'm using JPA2 and Hibernate implementation. I've got simple mapping like this: @Entity class Topic { @Id @GeneratedValue(strategy = IDENTITY) int id; @OneToOne(cascade = ALL) @JoinColumn(name = "id_poll") private Poll…
Dawid
  • 644
  • 1
  • 14
  • 30
8
votes
2 answers

Automatically create One-To-One relation when using reverse field

When creating two instances of a model and connecting them using a OneToOneField, the connection gets created and saved automatically at object creation: from django.db import models class MyModel(models.Model): name =…
7
votes
1 answer

Doctrine optional OneToOne mapping

I'm trying to create a optional OneToOne mapping in Doctrine. I have a table with all cities and zip codes available (this table shouldn't be changed), and I have a table with addresses and a mapped city. But sometimes I don't want to add City to my…
jayv
  • 495
  • 4
  • 13
7
votes
4 answers

ORM: OneToOne mapping on Non Primary-Key Join column - Book and Inventory mapped by ISBN

I have a Book model and Inventory model mapped by ISBN number, but ISBN is not the primary key in either. Books belong to Bookstores and Inventory is for a group of Bookstores(BookstoreChain). Inventory is shared by all Bookstores belonging to a…
Sathish
  • 20,660
  • 24
  • 63
  • 71
7
votes
1 answer

Why can't hibernate lazily fetch @ManyToOne and @OneToOne?

After some frustrating issues and tests, I've read that hibernate can't lazily fetch ToOne relationships. From what I've read, hibernate lazily fetches ToMany by setting its own Set as a proxy, and when a method is called on that Set, it fetched the…
elcye
  • 139
  • 1
  • 9
7
votes
1 answer

@OneToOne make primary key as foreign key at the same time (Spring JPA/Hibernate)

I've an entity like this: @Entity public class Person { @Id private Long id; private String firstName; // Getters and setters } The id is not autogenerated, but decided by the user. I have a second entity like…
Andrea Bevilacqua
  • 1,197
  • 3
  • 15
  • 27
7
votes
1 answer

How does django one-to-one relationships map the name to the child object?

Apart from one example in the docs, I can't find any documentation on how exactly django chooses the name with which one can access the child object from the parent object. In their example, they do the following: class Place(models.Model): …
Herman Schaaf
  • 46,821
  • 21
  • 100
  • 139
7
votes
1 answer

Secondarytables or OnetoOne associations?

Considering the following "model": USER Long: PK String: firstName String: lastName USER_EXT Long: PK String: moreInfo Date: lastModified I'm trying to find/create the correct Hibernate mapping (using Annotations) such…
David
  • 910
  • 1
  • 12
  • 22
7
votes
2 answers

How to do this Unidirectional NHibernate one-to-one mapping?

This is a problem of unidirectional one-to-one mapping in NHibernate. Student.cs public class Student { public int ID { get; set; } public int Roll { get; set; } public int RegNo { get; set; } public string Name { get; set; } …
user366312
  • 16,949
  • 65
  • 235
  • 452
7
votes
2 answers

How to serialize a relation OneToOne in Django with Rest Framework?

I have a class PersonProfile, and a class Person. In the class Person i have a relationship OneToOne with PersonProfile. How can i Serialize that? class PersonProfile(models.Model): interests = models.CharField(max_length=200, blank=True) …
WitaloBenicio
  • 3,395
  • 5
  • 25
  • 32
7
votes
2 answers

Does Django OneToOneField needs to be unique?

I get a "column template_id is not unique" error, now let me explain. I have a template model and a player version of it. Template: class FarmTemplate(models.Model): """Template of the "Farm" building""" name =…
Hans de Jong
  • 2,030
  • 6
  • 35
  • 55
7
votes
2 answers

OneToOne relationship for a non primary key column

I'm having a problem when I query an entity who has a OneToOne relationship with another one. This is the scenario: Database tables: create table people ( id decimal(10,0) NOT NULL, email varchar(512) NOT NULL ); create table users ( …
RDV
  • 193
  • 1
  • 3
  • 16