one-to-one

Nullable One To One Relationships with Integer Keys in LINQ-to-SQL

I have two objects (Foo and Bar) that have a one-to-zero-or-one relationship between them. So, Foo has a nullable foreign key reference to Bar.ID and a (nullbusted) unique index to enforce the "1" side. Bar.ID is an int, and so Foo.BarID is a nullable int. The problem occurs in the LINQ-to-SQL DBML mapping of .NET types to SQL datatypes...

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; } public StudentDetail StudentDetail { get; set; } } StudentDetail.cs public class Studen...

@OneToOne and @JoinColumn, auto delete null entity , doable?

I have two Entities , with the following JPA annotations : @Entity @Table(name = "Owner") public class Owner implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; @OneToOne(fetch=FetchType.EAGER , cascade=CascadeType.ALL) @JoinColumn(name="Data_id") private Dat...

In a One to One relationship should i drop one of the table's id column?

I have the following 2 tables in MySQL: Customer(Id, Firstname, Lastname...) Bonus(Id, CustomerId, Value, ...) The relation is One-To-One, every customer has only one bonus.(the CustomerId is unique in the Bonus Table) Q: Should I drop the Id column of the Bonus table? (I want to know why or why not) ...

Hibernate collection fetching optimally

I have the following structure Store Rebate RebateMetadata RebateCommission So, the relation is like this - Store -> Rebate is a one to many relation Rebate -> RebateMetadata is a one-to-one mapping Rebate -> RebateCommission is a one-to-one mapping My Query is to load all stores. And with it, load all Rebates ...

One to one relationship in Sql Server and LINQ

I have a Users table and a profile table. The reason they are separate is because information about the user can be put in before they are registered for the site. The problem I'm running into is that when I set the relationship in Sql Server it wants to create a one to many relationship. I don't see any way to change this. ...

has one relationships and deletion in grails

How should i delete the child object in a hasOne relationship in grails for eg: class Face { static hasOne = [nose: Nose] } class Nose { Face face static belongsTo= Face } i tried deleting the child object by two ways 1. face.nose.delete() 2. nose.delete() I always get the same exception Deleted object resaved by cascade in both...

One to one relationship mapping with composite key

Hi everybody, I have a database like this: My question is "How to mapping this database using castle active record?" I've tried this code: Campaign: [ActiveRecord("[Campaign]")] public class Campaign : ActiveRecordBase<Campaign> { private long m_ID; [PrimaryKey(Column = "`ID`")] public long ID {...

modeling a "one-to-one" relation in a database is the same than modeling "inheritance"?

Hi, i was wondering if there's a difference between modeling a one-to-one relation and a inheritance relation (Table-Per-Type) In both cases we add a foreing key with a UNIQUE constraint, or somethimes the FK is part of the PK It seems to me that the table structure is the same, but maybe i'm missing something. Thanks in advance. ...

Hibernate+JPA One To One relationship

I have a OneToOne relationship like this :- Person Others ----------- ------------- | id (PK) | <----------------->| id(PK)(FK) | ----------- ------------- | name | |.... | | address | |.... | | .... | ...

Hibernate JPA one-to-one saving child class entity

I have a one-to-one relationship using PrimaryKeyJoinColumn annotated on the parent side. And now I want to save the child entity by itself. For example, I have Employee and EmpInfo as the child entity, I need to save EmpInfo (of course after setting the id property of the parent to it). However, when such an arrangement is used, I get ...

Convert many to many to one to one (mysql)

We changed database schema and moved a relationship between users/accounts from a 1-1 to a many to many using a join table accounts_users. So we have accounts, users, accounts_users (user_id and account_id) Our data is still 1-1, and we have decided to move back. So I need sql to move back: To Migrate I used: INSERT INTO accounts_us...

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 that, with an HQL query as simple as "from User", it would generate the following SQL: sel...

(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 lastName; @OneToOne @PrimaryKeyJoinColumn private UserExt userExt; ... //getters...

In RDBMS, when a relation is one-to-one, does it help if both records point to each other, or is one pointing already enough (no need both pointing)?

I was reading a book and it talks about a User has some more UserDetail, and so the UserDetail will have a user_id pointing back to the Users table. I kind of forgot that, does it help at all to has a field in Users table to have a user_detail_id to point at the UserDetail record? This is so in Ruby on Rails too, that the Users table d...

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

Hi 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): name = models.CharField(max_length=50) address = models.CharField(max_len...

How do I setup one-to-one relationship in nhibernate? (currently doesn't return the foreign object)

I have a User, some of which are an employee. This is a one-to-one relationship and not all users are employees. When I get a user it doesn't seem to be bring back the employee information it just has it marked as null. I thought I have got my head around nhibernate but I have tried playing with so many properties on the mapping files a...

nhibernate inheritance

I have two tables: call_records crm_call_records call_records do not know that crm_call_records and their corresponding classes exists in different assemblies. I can therefore not add a subclass mapping in the mapping file for call_records. crm_call_records has a column named call_record_id which contains the value of the PK in cal...

NHibernate one-to-one mapping, non-primary keys

Can't get NHibernate to generate the correct query. It keeps using the primary keys of the two tables I'm joining for the one-to-one relationship, and I can't figure out how to specify the foreign key in one of the tables. tableA tableB { aID, { bID, bID, z, c, y, d } x } so the tableA should jo...

NHibernate: Composite key many-to-one mapping: Can't resolve property (foreign key component)

Hi guys, I hope anyone can help. I have to develop up against this third party database and I am kind of stuck with their crappy design. Still, I want to use NHibernate so I will have to jump through hoops. Simplified, there is this "Event" table that has a relation a "Transportation" table. The transportation table has a composite p...