composite-key

How to write JPQL SELECT with embedded id?

怎甘沉沦 提交于 2019-11-27 11:40:39
问题 I'm using Toplink essentials (JPA) + GlassFish v3 + NetBean 6.9 I have one table with composite primary key: table (machine) ---------------- |PK machineId | |PK workId | | | |______________| I created 2 entity classes one for entity itself and second is PK class. public class Machine { @EmbeddedId protected MachinePK machinePK; //getter setters of fields.. } public class MachinePK { @Column(name = "machineId") private String machineId; @Column(name = "workId") private String workId; } Now..

Why are composite keys discouraged in hibernate?

半世苍凉 提交于 2019-11-27 09:17:37
问题 This is from Hibernate official tutorial: There is an alternative <composite-id> declaration that allows access to legacy data with composite keys. Its use is strongly discouraged for anything else. Why are composite keys discouraged? I am considering using a 3-column table where all of the columns are foreign keys and together form a primary key that is a meaningful relationship in my model. I don't see why this is a bad idea, espicially that I will be using an index on them. What's the

SQL Primary Key - is it necessary?

旧巷老猫 提交于 2019-11-27 08:04:43
问题 I have a list of items. Most of these items will not be in stock. The item table has id, name, description. The quantities of items are stored in another table named inventory. The inventory table has item_id and quantity of items that are in stock. Do I need a primary key for the inventory table? If so, should I use a serial or composite key? When is it ok for a table to not have a primary key? Edit: Thank you all for being very informative. I will now always have primary keys except in very

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

送分小仙女□ 提交于 2019-11-27 07:44:27
问题 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? 回答1: You can only use Session.Get() if you used a key class as suggested here: nHibernate Composite Key Class Type Mismatch 回答2: With this composite key mapping: <class name="MyClass"> <composite-id> <key-property name="Key1" /> <key-property name="Key2" /> </composite-id> <property name="..." /> </class> ..

Defining Composite Key with Auto Increment in MySQL

。_饼干妹妹 提交于 2019-11-27 07:07:17
Scenario: I have a table which references two foreign keys, and for each unique combination of these foreign keys, has its own auto_increment column. I need to implement a Composite Key that will help identify the row as unique using combination of these three (one foreign keys and one auto_increment column, and one other column with non-unique values) Table: CREATE TABLE `issue_log` ( `sr_no` INT NOT NULL AUTO_INCREMENT , `app_id` INT NOT NULL , `test_id` INT NOT NULL , `issue_name` VARCHAR(255) NOT NULL , primary key (app_id, test_id,sr_no) ); Of course, there has to be something wrong with

@OneToMany and composite primary keys?

点点圈 提交于 2019-11-27 07:06:03
I'm using Hibernate with annotations (in spring), and I have an object which has an ordered, many-to-one relationship which a child object which has a composite primary key, one component of which is a foreign key back to the id of the parent object. The structure looks something like this: +=============+ +================+ | ParentObj | | ObjectChild | +-------------+ 1 0..* +----------------+ | id (pk) |-----------------| parentId | | ... | | name | +=============+ | pos | | ... | +================+ I've tried a variety of combinations of annotations, none of which seem to work. This is the

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

与世无争的帅哥 提交于 2019-11-27 04:04:59
问题 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"

hibernate composite key

寵の児 提交于 2019-11-27 03:54:23
Is it necessary that composite-id should be mapped to class ?? can it be like this ? <composite-id> <key-property=..../> <key-property=..../> </composite-id> or should be <composite-id class=....> <key-property=..../> <key-property=..../> </composite-id> should that necessary that if we have composite key then that class should implement equals() and override() method ? Lachlan Roche Hibernate needs to be able to compare and serialize identifiers. So the identifier class must be serializable, and override hashCode() and equals() consistently with the database's notion of composite key equality

Composite Key with EF 4.1 Code First

倾然丶 夕夏残阳落幕 提交于 2019-11-27 03:02:10
I am trying to figure out how to have a composite key using EF code First 4.1 RC. Currently, I am using the [Key] Data Annotation, but I am unable to specify more than one key. how would one specify a composite key? Here is my Example: public class ActivityType { [Key] public int ActivityID { get; set; } [Required(ErrorMessage = "A ActivityName is required")] [StringLength(50, ErrorMessage = "Activity Name must not exceed 50 characters")] public string ActivityName { get; set; } } I need the "ActivityName" to also be a key. Sure, I can code around this, but thats not good database design. You

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

别说谁变了你拦得住时间么 提交于 2019-11-27 01:00:58
问题 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? 回答1: You could also use HasKey(u => new { u.SubscriptionID, u.UserName