one-to-one

Nhibernate One-to-one mapping issue with child object insert error

假装没事ソ 提交于 2019-11-29 08:08:15
i've being banging my head against the desk all day with the following Nhibernate problem. Each bank account has one (and only one) set of rates associated with it. The primary key of the bank account table, BankAccountID is also a foreign key and the primary key in the AccountRate table. public class BankAccount { public virtual int BankAccountId { get; set; } public virtual string AccountName { get; set;} public virtual AccountRate AccountRate {get;set;} } public class AccountRate { public virtual int BankAccountId { get; set; } public virtual decimal Rate1 { get; set; } public virtual

Need an example of a primary-key @OneToOne mapping in Hibernate

谁说我不能喝 提交于 2019-11-29 04:52:34
Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in Hibernate ? I've tried numerous combinations, and so far the best thing I've gotten is this : @Entity @Table(name = "paper_cheque_stop_metadata") @org.hibernate.annotations.Entity(mutable = false) public class PaperChequeStopMetadata implements Serializable, SecurityEventAware { private static final long serialVersionUID = 1L; @Id @JoinColumn(name = "paper_cheque_id") @OneToOne(cascade = {}, fetch = FetchType.EAGER, optional = false, targetEntity = PaperCheque.class) private PaperCheque paperCheque; }

Why @OneToOne is allowing duplicate associations?

你。 提交于 2019-11-29 02:14:42
问题 I have User and Address classes as follows: class User { ... ... @OneToOne( cascade=CascadeType.ALL) @JoinColumn(name="addr_id") private Address address; } class Address { ... ... @OneToOne(mappedBy="address") private User user; } Here my assumption is with this domain model I can associate one address to only one user(user.addr_id should be unique). But with this domain model, I am able to create multiple users and associate them to the same address. User u1 = new User(); //set data Address

Why hibernate perform two queries for eager load a @OneToOne bidirectional association?

馋奶兔 提交于 2019-11-29 01:02:35
问题 i have entity A that has-a B entity, and B has-a A with @OneToOne bidirectional association. Now, when i findall A records, hibernate perform two queries with a left outer join on B, something like this: select a.id, a.id_b, a.field1, b.id, b.field1 from A as a, B as b left outer join b ON b.id=a.id_b; select a.id, a.id_b, a.field1, b.id, b.field1 from A as a, B as b left outer join b ON b.id=a.id_b WHERE b.id=? First query load A and B fields and it is ok, but why perform second query to

Hibernate ManyToOne vs OneToOne

孤街浪徒 提交于 2019-11-28 18:36:47
I can't see any difference in the schema of a Many-To-One relationship vs a OneToOne relationship: @Entity public class Order { @ManyToOne @JoinColumn(nullable = false) private Address address; vs @Entity public class Order { @OneToOne @JoinColumn(nullable = false) private Address address; Is there any difference? They look exactly the same on schema but there is difference on Hibernate Layer. If you try something like that: Address address = new Address(); Order order1 = new Order(); order1.setAddress(address); Order order2 = new Order(); order2.setAddress(address); save(); Everything will be

MySQL - One To One Relation?

妖精的绣舞 提交于 2019-11-28 16:25:25
问题 I'm trying to achieve One To One relation in MySQL database. For example, let's say I have Users table and Accounts table. And I want to be sure there is User can have only one account. And that there can be only one Account per user. I found two solutions for this but don't know what to use, and are there any other options. First solution: DROP DATABASE IF EXISTS test; CREATE DATABASE test CHARSET = utf8 COLLATE = utf8_general_ci; USE test; CREATE TABLE users( id INT NOT NULL AUTO_INCREMENT,

Both One-To-One and One-To-Many relationships in Entity Framework 5 Code First

醉酒当歌 提交于 2019-11-28 12:27:39
i tried the whole day to get this working. I learned a lot about EF's Fluent API (e.g. this is an excellent article), however i had no success. I have three Entities: public class Address { [Key] public virtual int AddressId { get; set; } public virtual string AddressString { get; set; } } public class User { [Key] public virtual int UserId { get; set; } public virtual ICollection<Address> Addresses { get; set; } } public class House { [Key] public virtual int HouseId { get; set; } public virtual Address Address { get; set; } } and tried all combinations of HasMany, HasOptional, WithOptional,

How to set the one-to-one relationship with fluent api in this case? (EF6)

删除回忆录丶 提交于 2019-11-28 06:52:12
问题 I have this two entities: public partial class Ficheros { public Guid Idfichero { get; set; } public long Iddocumento { get; set; } public byte[] Fichero { get; set; } public virtual Documentos IddocumentoNavigation { get; set; } } public partial class Documentos { public Documentos() { ElementosDocumentos = new HashSet<ElementosDocumentos>(); } public long Iddocumento { get; set; } public string Nombre { get; set; } public long? IdtipoDocumento { get; set; } public string Codigo { get; set;

Django Admin: OneToOne Relation as an Inline?

时光怂恿深爱的人放手 提交于 2019-11-28 03:22:48
I am putting together the admin for a satchmo application. Satchmo uses OneToOne relations to extend the base Product model, and I'd like to edit it all on one page. It is possible to have a OneToOne relation as an Inline? If not, what is the best way to add a few fields to a given page of my admin that will eventually be saved into the OneToOne relation? for example: class Product(models.Model): name = models.CharField(max_length=100) ... class MyProduct(models.Model): product = models.OneToOne(Product) ... I tried this for my admin but it does not work, and seems to expect a Foreign Key:

Nhibernate One-to-one mapping issue with child object insert error

拜拜、爱过 提交于 2019-11-28 01:45:46
问题 i've being banging my head against the desk all day with the following Nhibernate problem. Each bank account has one (and only one) set of rates associated with it. The primary key of the bank account table, BankAccountID is also a foreign key and the primary key in the AccountRate table. public class BankAccount { public virtual int BankAccountId { get; set; } public virtual string AccountName { get; set;} public virtual AccountRate AccountRate {get;set;} } public class AccountRate { public