one-to-one

Hibernate: @ManyToOne(fetch = FetchType.LAZY) does not work on non-primary key referenced column

江枫思渺然 提交于 2019-12-10 01:15:50
问题 I have 2 tables: Order [OrderId(PK), OrderShipmentCode, ...] and Shipment[ShipmentId(PK), ShipmentCode, ...] . In Order class, I declared shipment field as follows: @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "OrderShipmentCode", referencedColumnName = "ShipmentCode", insertable = false, updatable = false, nullable = false) private Shipment shipment; When I get the list of Order , the Shipment is also loaded (I saw many separate SELECT queries). But I want the Shipment to be lazy

Optional one-to-one mapping in Hibernate

℡╲_俬逩灬. 提交于 2019-12-09 14:19:45
问题 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 file: User Class: <one-to-one name="lastVisitedPage" class="LastVisitedPage" cascade="save-update"> LastVisitedPage Class: <one-to-one name="user" class="user" constrained="true" /> The above example does not allow the creation of a user who does not

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

耗尽温柔 提交于 2019-12-09 08:41:10
问题 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

Generic one-to-one relation in Django

爱⌒轻易说出口 提交于 2019-12-09 02:10:28
问题 I need to set up one-to-one relation which must also be generic. May be you can advice me a better design. So far I came up to the following models class Event(models.Model): # skip event related fields... content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') class Meta: unique_together = ('content_type', 'object_id') class Action1(models.Model): # skip action1 related fields... events =

Hibernate one-to-one mapping with a reference column (XML mapping)

那年仲夏 提交于 2019-12-09 01:02:10
问题 I have a user table and a user_detail table with one to one mapping user_detail table have a field user_id to be used for this relation which stores id field value of corresponding user. How to write the hibernate hbm file for this relation? UPDATE what my problem is that user's primary key is id , user_detail's foreign key is user_id all the examples i got in internet users user_id as users primary key and the same as foreign key in other table 回答1: For User mapping.... <?xml version="1.0"?>

Does Django OneToOneField needs to be unique?

这一生的挚爱 提交于 2019-12-08 20:27:00
问题 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 = models.CharField(max_length=23) flavor = models.TextField() resource = models.CharField(max_length=23) version = models.FloatField(unique=True) def __unicode__(self): return self.name My User model: class Farm(models.Model): """Keeps track of Townhall""" user = models.ForeignKey(User)

EF: one-to-one relationship

血红的双手。 提交于 2019-12-08 19:32:26
I am trying to set up a bi-directional one-to-one relationship. However, I am failing to get a bi-directional setting for two entities. For example, lets say one person has one phone number, and one phone number can only be associated to one person. I would have: public class Person : Entity { public long PersonId { get; set; } public virtual PhoneNumber PhoneNumber {get; set; } } public class PhoneNumber : Entity { public long PhoneNumberId { get; set; } } However, with this re-arrangement, I cannot get a bi-directional setting. i.e. I cannot have phoneNumber.Person. What I have tried: public

error saving OneToMany and ManyToMany relationship with Doctrine 2

霸气de小男生 提交于 2019-12-08 13:40:35
I have a problem with "Doctrine2". When attempting to save a relationship "ManyToMany" or "OneToOne" PHP leave exception error! I leave the error so that you can help me. Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A new entity WAS found Through the Relationship' Entities \ User # privilege 'That Was not configured to cascade persist Operations for entity: Entities \ Privilege @ 0000000012feb12000000000616126d4. Explicitly or persist the new entity set up cascading persist Operations on the relationship. If you can not find out Which Causes the problem by

add fields to model from another one related with OneToOneField or ForeignKey relation

爷,独闯天下 提交于 2019-12-08 13:17:06
问题 i am new to django and i am using the 1.11 version i have several models some related with foreign keys and some with oneToOne relation. for instance the user and profile models, i would like to add in the profile form fields from the user form how? For the oneToOne, I have the an admin model with a oneToOne field related to the user model. but not just admin, i have several types of user (admin, writer, commetator, ...) each in a different model and when creating one type i also create its

NHibernate - one-to-one Mapping

与世无争的帅哥 提交于 2019-12-08 13:03:15
问题 I have a one-to-one relationship between a Person class and an Employee. I expect the INSERT to cascade from the Person to the Employee. However, this does not happen. I've tried cascade='all' and cascade='save-update' on one-to-one relationship element, but it didn't work. I have also uploaded my entire source code on: http://bit.ly/gnkxBr (3.52 MB) The structures of the my objects are as follows: public class Person { public virtual Employee Employee { get; set; } public virtual int Age {