one-to-one

one-to-one mapping is not working with 2nd-Level-Cache

只谈情不闲聊 提交于 2019-12-04 18:21:24
I have declared the fallowing mapping with NHibernate3: with FluentNHibernate public class ActivityMap : ClassMap<Activity> { public ActivityMap() { this.Table("Activity"); this.Cache.ReadWrite(); this.Version(x => x.ObjectVersion); this.Id(x => x.Id).GeneratedBy.Assigned(); // snipp this.HasOne(x => x.AppointmentRecurrence).Cascade.Delete(); } } public class AppointmentRecurrenceMap : ClassMap<AppointmentRecurrence> { public AppointmentRecurrenceMap() { this.Table("AppointmentRecurrence"); this.Cache.ReadWrite(); this.Version(x => x.ObjectVersion); this.Id(x => x.Id).GeneratedBy.Foreign(

Linq 2 SQL One to Zero or One relationship possible?

流过昼夜 提交于 2019-12-04 18:19:06
Is it possible to create a one to zero or one relationship in Linq2SQL? My understanding is that to create a one to one relationship you create a FK relationship on the PK of each table. But you cannot make the PK nullable, so I don't see how to make a one to zero or one relationship work? I'm using the designer to automatically create the model - so I would like to know how to set up the SQL tables to induce the relationship - not some custom ORM code. You're partially correct...but your mixing things a little. You cannot make a primary key field null. That part is correct. But the foreign

Check if a OneToOne relation exists in Django

▼魔方 西西 提交于 2019-12-04 17:56:20
问题 Now I'm using django 1.6 I have two models relates with a OneToOneField . class A(models.Model): pass class B(models.Model): ref_a = models.OneToOneField(related_name='ref_b', null=True) First see my code that points out the problem: a1 = A.objects.create() a2 = A.objects.create() b1 = B.objects.create() b2 = B.objects.create(ref_a=a2) # then I call: print(a1.ref_b) # DoesNotExist Exception raised print(a2.ref_b) # returns b2 print(b1.ref_a) # returns None print(b2.ref_a) # returns a2 Now the

JPA unidirectional @OneToOne vs @ManyToOne with Hibernate - no difference?

你。 提交于 2019-12-04 14:08:10
According to book Pro JPA 2 the main difference between unidirectional @ManyToOne and @OneToOne is that in @OneToOne: Only one instance of the source entity can refer to the same target entity instance. In other words, the target entity instance is not shared among the source entity instances. In the database, this equates to having a uniqueness constraint on the source foreign key column (that is, the foreign key column in the source entity table). The thing is, when I create such a mapping on entity and let Hibernate create schema, there is no unique constrain created at all. Why? Because of

SQLAlchemy query filter on child attribute

喜欢而已 提交于 2019-12-04 10:04:45
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", uselist=False, lazy='joined') class Child(Base): __tablename__ = 'child' child_id = Column(Integer, ForeignKey(Parent.id), primary_key=True) value = Column(Integer) my test data are the following: q = s.query(Parent) pd.read_sql(q.statement,s.bind) id name child_id value 1 a 1 10 2 b 2 20 3 c 3 30 Now I'd like to get only the parents with child.value > 20 using this query

Creating PostgreSQL tables + relationships - PROBLEMS with relationships - ONE TO ONE

泪湿孤枕 提交于 2019-12-04 08:41:24
问题 So I am supposed to create this schema + relationships exactly the way this ERD depicts it. Here I only show the tables that I am having problems with: So I am trying to make it one to one but for some reason, no matter what I change, I get one to many on whatever table has the foreign key. This is my sql for these two tables. CREATE TABLE lab4.factory( factory_id INTEGER UNIQUE, address VARCHAR(100) NOT NULL, PRIMARY KEY ( factory_id ) ); CREATE TABLE lab4.employee( employee_id INTEGER

Django OneToOneField - in which model should I put it?

自闭症网瘾萝莉.ら 提交于 2019-12-04 08:29:51
问题 Let's assume that we have the following models. class A(Model): pass class B(Model): pass Then there is no difference between: In model A: b = OneToOneField(B, related_name=A.__name__) and in model B: a = OneToOneField(A, related_name=B.__name__) So what questions should I ask myself to decide whether to put OTO in one model or another. I mean like has-a, is-a and so on. 回答1: There actually is a difference in where you put the one-to-one field, because deletion behaves differently. When you

Referential integrity with One to One using hibernate

安稳与你 提交于 2019-12-04 04:21:08
问题 I'm having two tables - Foo { foo_id, name } Foo_properties { fp_id, foo_id, phoneNumber} Now I want to map this in my object model using hibernate.. I need a foo_id in Foo_properties because i want to maintain referential integrity and want to add ON DELETE CASCADE constraint. so I mapped the relation in the following way - @Entity public class Foo{ @Id private long foo_id; private String name; @OneToOne(mappedBy = "foo") private FooProperties fooProperties; } @Entity public class

Hibernate one-to-one entity association with shared PK between 3 classes

喜你入骨 提交于 2019-12-03 14:34:28
I want a unidirectional one-to-one relationship between objects of 3 java classes: Person to Heart, and Person to Liver. I want the objects to share the same PK i.e. every person has a corresponding heart and liver, where person.person_id = heart.heart_id = liver.liver_id. I do not want to merge the 3 tables into 1 because each has loads of fields. Here's my code (mostly based on the accepted answer for this question ): @Entity public class Person { public long personId; private String name; public Heart heart; public Liver liver; // other fields @Id @GeneratedValue public long getPersonId()

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

喜欢而已 提交于 2019-12-03 11:06:35
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 I have to map a legacy schema which I cannot change and that this schema uses a shared primary key between two entities which at the same time is the foreign key for one entity. I created a simple TestCase: DB looks as follows: CREATE TABLE PARENT (PARENT_ID Number primary key, Message varchar2(50)); CREATE TABLE CHILD (CHILD_ID Number primary key,