composite-key

Entity framework multiple composite keys, cascade on delete

女生的网名这么多〃 提交于 2019-12-12 05:57:32
问题 I'm having a bit of a problem with configuring composite keys in Entity framework between 3 tables, code first approach. I have a base class that has the Id, which all of my classes inherit from. The first table has a collection of the second table items, while it has a collection of the third table. I need composite keys for cascade on delete when removing an element from either table. I am also using the aggregate root pattern. public abstract class BaseClass { [Key, Column(Order = 0)]

One-to-Many With Composite Keys and Different Column Names in Grails

谁都会走 提交于 2019-12-12 04:37:05
问题 This is a syntax question. I want a one-to-many relationship between Foo -> Bar (simplified here): class Foo { String fooPK1, fooPK2 static mapping = { id composite: ["fooPK1", "fooPK2"] } static hasMany = [bars: Bar] } class Bar { String fooPK1, dumbNameForFooPK2, barPK1, barPK2 Foo myFoo static mapping = { id composite: ["barPK1", "barPK2"] columns { myFoo[:] { column name: "FOO_PK_1" column name: "?????????????" } } } } In this case, obviously Foo.fooPK1 maps to Bar.fooPK1, but i need Foo

Hibernate Entity mapping when Foreign key is part of the composite primary key?

蓝咒 提交于 2019-12-12 02:17:28
问题 I have a Table with a composite PK : Customer I have a View with no PK : Purchase To bind my Entity, Hibernate forces me to declare a PK. So I've created a composite PK For Purchase. Puchase: @Entity @Table(name = "PURCHASE") public class Purchase { @EmbeddedId private PurchasePK id; } PuchasePK: @Embeddable public class PurchasePK { @Column(name = "CUST_LASTNAME") private String custLastname; @Column(name = "OBJ_NAME") private Long objectName; } Customer is straight forward : @Entity @Table

Using one of the columns in a composite key as a foreign key

感情迁移 提交于 2019-12-12 02:15:46
问题 I was trying to see whether I can use one of the columns in a composite key as a foreign key. And I got strange result. CREATE TABLE TESTPARENT( PK1 INT, PK2 INT, PRIMARY KEY(PK1,PK2) ); Query OK, 0 rows affected (0.01 sec) CREATE TABLE TESTCHILD1( FK1 INT, FOREIGN KEY (FK1) REFERENCES TESTPARENT(PK1) ); Query OK, 0 rows affected (0.01 sec) CREATE TABLE TESTCHILD2( FK2 INT, FOREIGN KEY (FK2) REFERENCES TESTPARENT(PK2) ); ERROR 1005 (HY000): Can't create table 'test.TESTCHILD2' (errno: 150)

Is it possible to map a composite key in fluent nhibernate where half of the key is an identity field in the database?

醉酒当歌 提交于 2019-12-11 23:12:00
问题 As the question states, is it possible to map a composite key in fluent nhibernate (or non fluent i suppose) where one of the two fields used in the composite is an identity field? I have a table where one part of the primary key is an identity field and the other is a tenant id. This is a legacy database where the composite key is used as foreign keys all over, so modifying the database would be quite significant. thanks! 回答1: If it's really an identity column, then it's guaranteed to be

Nhibernate composite key question

佐手、 提交于 2019-12-11 21:52:03
问题 I have a table called person_skills like so: person_id, skill_type_id, base_score, misc_score There is a lookup table that contains id, name for skill_types. Now the tricky thing is that I have a composite key for person_id, skill_type_id. There will be many entries within this table as a person may have 5 skills. Currently I have got a class like so: public class skill { int BaseScore {get;set;} int MiscScore {get;set;} } Then I have a class to contain all this like below: public class

JPA: Entity mapping with composite primary key and single key

三世轮回 提交于 2019-12-11 12:10:46
问题 JPA 2, Hibernate 4. Creating entities from a database view. I'm having difficulty getting these two entities to map correctly. I have a parent Entity with a composite key, and a child Entity with a single value key. The relationship between the two is defined by the Child entity having part of the Parent's composite key. Trying to make the association between the two. Composite Key Class @Embeddable public Class ParentID implements Serializable { private static final long serialVersionUID =

Creating a Dictionary Composite Key out of Every Permutation in a String[] within a String[][]

蹲街弑〆低调 提交于 2019-12-11 10:33:10
问题 I have a Dictionary<string,string> that is acting as the composite key for another Dictionary . I also have some string[] arrays that contains the necessary strings to be used as the composite key. For example: //Dictionary that will use composite key Dictionary<Dictionary<string, string>, decimal> lookUpDictionary = new Dictionary<Dictionary<string, string>, decimal>(); //The composite key dictionary Dictionary<string, string> compositeKey = new Dictionary<string, string>(); //Array

Components as composite identifiers in Hibernate

老子叫甜甜 提交于 2019-12-11 09:35:32
问题 I am following Hibernate Documentation and trying to implement the example given for section 9.4. Components as composite identifiers but facing issues on how to implement it. Here is what I have done: My entity classes: Order.java public class Order { private int id; private Set<OrderLine> lines = new HashSet<OrderLine>(); // Setters & Getters } OrderLine.java public class OrderLine { private OrderLineId id; private String name; private Order order; // Setters & Getters } OrderLineId.java

Unexpected proxy objects in Nhibernate with composite ID's

♀尐吖头ヾ 提交于 2019-12-11 08:42:37
问题 I have a data structure which uses composite ids (Which I dont wish to change to single) Everything loads fine except for many-to-one joins which if the join is empty, instead of mapping the property to null, maps it to an empty proxy object. I have written an ugly work around( see bleow). Any solutions to this? private Node _Parent; public Node Parent { get { return this._Parent; } set { this._Parent = Proxy.Check<Node>(value); } } internal static class Proxy { public static T Check<T>(T obj