many-to-one

Deleting an object that references itself with NHibernate 2.0.1.GA

I've recently upgraded from NHibernate 1.2 to NHibernate 2.0.1.GA and an issue has occurred attempting to delete an object that references itself. The mapping file: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" ..> <class name="Account" table="Account" polymorphism="explicit"> <id name="ID" column="ID"> <g...

NHibernate many-to-one relationship deleting parent only

I have a many-to-one relationship between objects Product and Supplier. I need to be able to delete Supplier without deleting the Products that belong to it. Here is a simplified version of classes: public class Supplier { public virtual IList<Product> Products { get; protected set; } } public class Product { // Product belong...

Hibernate - child collection Identifier changed in update

Hi guys, when I trying to update the object RFQ , Hibernate tends to update its child collection BQMaster and trying to set and update the identifier of BQMaster which normally it should not be allowed. The postgre log file: *2009-05-22 11:16:53 ERROR: duplicate key violates unique constraint "bq_masters_pkey"* *2009-05-22 11:16:53 STAT...

NHibernate - Multiple one-to-many relations

I have very simple object structure for Person's and their marriage relations. I have exactly same structure in the db as well. public class Person { public virtual string Id { get; set; } public virtual ISet MarriageRelations { get; set; } } public class MarriageRelation { internal virtual int Id { get; set; } public vi...

How to lazy load a one-to-one composition via hql

If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B. The mapping is as follows: <class name="EntityA" table="TABLE_A" mutable="true" lazy="true"> <id name="idA" type="long" column="pk_a" unsaved-value="null"> <generator class="sequence"> <param name="sequence">pk_a_seq</param> ...

hibernate many-to-one hql query, when inner join fetch property not associated

I have a many-to-one association set up like this, in the hbm.xml: <many-to-one name="gigVenue" class="blah.blah.xxx" fetch="select" lazy="no-proxy" not-null="true" > <column name="N_VENUE_ID" precision="18" scale="0" not-null="true" /> </many-to-one> And I am using instrumentation to do true lazy loading. BUT when I run a hql query ...

Nhibernate many-to-one Composite key - if null then fails? is many-to-one or none possible?

Hi Have the mapping as shown below. this is from a leagcy db so have no control over changing the structure. The File record in some circumstances will not have a link to the DISPLAY3 table. Every file has a link to the DISPLAY2 table. However if the File.DISPLAy3 field is null then is does not have a link to the DISPLAY3 only the DISPL...

Person -> Details with lazy loading

Yesterday I`ve asked a question Person -> Details database structure Now I need to make a NHibernate mapping, where the details are lazy loaded. so my person map is: <class name="Employee" table="Employee"> <id name="Id" column="EmployeeId"> <generator class="native" /> </id> <property name="FName" column="FName"/> ...

NHibernate many-to-one loading alternative?

I have a Parent/Child object/mapping as follows: class Parent { int Id; string name; List children; } <bag name="Children" cascade="all" lazy="false "> <key column="ParentId" /> <one-to-many class="Child" /> </bag> class Child { int Id; Parent Parent; string Name; } <many-to-one name="Parent" column="ParentId" /> O...

Correct NHibernate mapping for a specific scenario (one-to-many/one-to-one)

I had a following structure: User has many books in his history which was translated to the following class User { ICollection<Book> History } // C# User -> UserHistory (UserId, BookId) -> Book // DB Now I want to add a date to the history, creating the following class structure: class User { ICollection<Read> History } ...

NHibernate: mapping single column from many-to-one to a primitive type

I have a following mapping: <set name="People" lazy="true" table="ProjectPeople"> <key column="ProjectId" /> <composite-element class="PersonRole"> <many-to-one name="Person" column="PersonId" cascade="save-update" not-null="true" /> <many-to-one name="Role" column="RoleId" cascade="save-update" not-null="true" /> </compo...

NHibernate: SaveOrUpdate by <natural-id>

Is there an easy way to make NH INSERT or UPDATE an entity depending on whether there is already an entity with same <natural-id />? The entity is mapped to another (root) one using <many-to-one cascade="save-update" />. ...

NHibernate Many-to-Once Cascade

Hi, I have created the mapping shown below between Invoice and InvoiceDetail. When trying to update an Invoice, I notice an update statement for User as well. Why should “User” be updated when we have set cascade ="none"? <class name="Invoice" table="invoice" lazy="false"> <id name="InvoiceID" column="InvoiceID" type="int"> ...

Mapping db-imported countries to address entity with JPA

I ran some DDL script to setup a complete country table in my database. The country table's primary key column contains the corresponding ISO code for every country. In my JPA project I have a User entity having an embedded Address entity and this Address entity has a reference to a Country. The relationship between User and Address se...

LINQ to SQL - retrieve object, modify, SubmitChanges() creates new objects

I've been battling this for a while. I'm trying to implement a many to one association. I have a bunch of rows in a table, called readings. These accumulate over time, and every now and then I want to export them. When I export them I want to create a new object called ExportEvent, to track which rows were exported, so they can be re-exp...

NHibernate Many to One / One to One with differing keys

Hey all, I'm kicking the tires on NHibernate and have a conoundrum I have been scratching my head over for a bit now, working with a legacy database with some fairly complex relationships. ClaimRoot has a primary key of a claimGUID. ClaimRoot has a bag of Claimdetails associated by claimGUID (this works a treat). The problem is that C...

Rails ActiveRecord relationships - has many and belongs to associations

I've created 3 models: Article: contains an article Tag: contains tags ArticleTag: meant for associating a many-to-one tags to article relationship. It contains a tag_id and an article_id. The problem I'm having is I'm fairly new to the active record technology and I don't understand the proper way to define everything. Currently, wh...

Python many-to-one mapping (creating equivalence classes)

Hi, I have a project of converting one database to another. One of the original database columns defines the row's category. This coulmn should be mapepd to a new category in the new databse. For example, let's assume the original categories are:parrot, spam, cheese_shop, Cleese, Gilliam, Palin Now that's a little verbose for me, And ...

How can I specify dependency in JPA without links from owner entity?

The goal is to remove all Dependent when their Owner is deleted. I have the following classes: @Entity class Dependent { @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY, optional = false) @Column(name = "OWNER") private Owner _owner; } @Entity class Owner { ... } In the current implementation Dependen...

How do you delete a referenced object when the reference changes in NHibernate?

I have two entities like so (distilled to only what's relevant): public class Person { public virtual Address Address } public class Address { } Person has a many-to-one relationship with Address, or in object terms, a Person references an Address, and this link is uni-directional (Address does not have a reference back to Person...