composite-key

Using NHibernate's ISession.Get<>() w/ a composite key

青春壹個敷衍的年華 提交于 2019-11-28 13:29:10
I have a composite key in a database table / NHibernate entity. Can I somehow use the .Get method to grab a specific entity or do I have to use HQL / Criteria due to the composite key? lcranf You can only use Session.Get() if you used a key class as suggested here: nHibernate Composite Key Class Type Mismatch With this composite key mapping: <class name="MyClass"> <composite-id> <key-property name="Key1" /> <key-property name="Key2" /> </composite-id> <property name="..." /> </class> ...you can use .Get like this: var x = Session.Get<MyClass>(new MyClass() { Key1 = 'Foo', Key2 = 'Bar'}); 来源:

How to create a composite primary key which contains a @ManyToOne attribute as an @EmbeddedId in JPA?

旧街凉风 提交于 2019-11-28 10:13:34
I'm asking and answering my own question , but i'm not assuming i have the best answer. If you have a better one, please post it! Related questions: How to set a backreference from an @EmbeddedId in JPA hibernate mapping where embeddedid (?) JPA Compound key with @EmbeddedId I have a pair of classes which are in a simple aggregation relationship: any instance of one owns some number of instances of the other. The owning class has some sort of primary key of its own, and the owned class has a many-to-one to this class via a corresponding foreign key. I would like the owned class to have a

How do I map a composite primary key in Entity Framework 4 code first?

℡╲_俬逩灬. 提交于 2019-11-28 05:41:00
I'm getting to grips with EF4 code first, and liking it so far. But I'm having trouble mapping an entity to a table with a composite primary key. The configuration I've tried looks like this: public SubscriptionUserConfiguration() { Property(u => u.SubscriptionID).IsIdentity(); Property(u => u.UserName).IsIdentity(); } Which throws this exception: Unable to infer a key for entity type 'SubscriptionUser'. What am I missing? You could also use HasKey(u => new { u.SubscriptionID, u.UserName }); Edit: One limitation I have found is that the following do not work: public

Creating composite foreign key constraint

被刻印的时光 ゝ 提交于 2019-11-28 03:16:55
问题 I am trying to create a composite foreign key relationship/constraint. All tables are empty. I have this table: CREATE TABLE [dbo].[ChemSampleValueTest]( [SampleNumber] [int] NOT NULL, [ParameterID] [int] NOT NULL, [Value] [numeric](18, 6) NOT NULL, [Accuracy] [varchar](50) NULL, [ResultGroupID] [int] NOT NULL, [QAState] [nvarchar](32) NOT NULL, CONSTRAINT [PK_SampleValueTest] PRIMARY KEY CLUSTERED ( [SampleNumber] ASC, [ParameterID] ASC, [ResultGroupID] ASC ) ) ON [PRIMARY] and this table:

MySQL Question - Unique Key Not functioning correctly, or am I misunderstanding?

北城余情 提交于 2019-11-27 22:12:00
问题 I'm trying to create a relation where any of four different parts may be included, but any collection of the same parts should be handled as unique. Example: An assignment must have an assigned company, may optionally have an assigned location, workgroup and program. An assignment may not have a workgroup without a location. Let's assume we have companies A, B, C; locations X, Y, Z; workgroups I, J, K and programs 1, 2, 3. So valid relations could include A - X - I - 1 A - Z - 2 B - Y C C - 3

Should Hibernate be able to handle overlapping foreign keys?

牧云@^-^@ 提交于 2019-11-27 20:16:26
I have a table that has two foreign keys to two different tables with both foreign keys sharing one column : CREATE TABLE ZipAreas ( country_code CHAR(2) NOT NULL, zip_code VARCHAR(10) NOT NULL, state_code VARCHAR(5) NOT NULL, city_name VARCHAR(100) NOT NULL, PRIMARY KEY (country_code, zip_code, state_code, city_name), FOREIGN KEY (country_code, zip_code) REFERENCES Zips (country_code, code), FOREIGN KEY (country_code, state_code, city_name) REFERENCES Cities (country_code, state_code, name) ) As you can see, there are two FKs sharing country_code (coincidentally referencing the same column at

How to give a unique constraint to a combination of columns in Oracle?

心不动则不痛 提交于 2019-11-27 15:32:20
问题 I have a Table with 4 Columns Each Column will be A,B,C,D Column A is the Primary key. Column B has unique name constraint. Now I want to remove the unique constraint for column B and give a unique constraint by combining the columns B, C and D. So the table will allow only one row with a particular value in columns B,C and D. How can I give this type of a constraint? I tried giving the composite unique key like : ALTER TABLE TABLENAME ADD CONSTRAINT CONSTRAINT_NAME UNIQUE (COLUMN_B, COLUMN_C

Hibernate Issue : Foreign key must have same number of columns as referenced primary key

 ̄綄美尐妖づ 提交于 2019-11-27 14:13:34
Goal : I want to have importJobId in ImportJob as foreign key for id of allocation table, such that when we have importJobId then and then only we can have id in allocation as without Job there cannot be any allocations. ImportJob table has composite primary key as [ORGID,IMPORTJOBTYPE] and am trying to get create foreign key relationship in hibernate using <id name="id" column="ID"> <generator class="native"/> </id> <many-to-one name="importjobid" class="com.delta.pdo.admin.ImportJob" cascade="save-update"/> in Allocation.hbm.xml which is not working out and am getting error message as:

How can I use generated value within composite keys?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 12:27:23
问题 I have two classes documentlog and documentversion(with primary keys: int doc_id and int docVersionID) with a many-to-one relationship. I used a composite key class called CompundKey to manage the compound primary key. I need to auto increment docversionID but I am not able to do that. Could you please help me in this regard? @Entity @Table(name = "Documentversion", schema = "DocumentManagement") public class DocumentVersion implements Serializable { private CompoundKey id; private List

MySQL - Make a pair of values unique

非 Y 不嫁゛ 提交于 2019-11-27 11:56:14
问题 I have a table with two int values that are IDs. On their own these IDs can show up any number of times in the table, but together they should only ever appear once. Is there a way to make a pair of values unique and still allow the individual values to show up multiple times? As a follow up, if this is possible can the pair of values be used as a key? I currently have a 3rd column for a unique auto increment value for my key. 回答1: It's called a composite key. If you want to change your