composite-key

Hibernate foreign key with a part of composite primary key

 ̄綄美尐妖づ 提交于 2019-12-05 21:17:59
问题 I have to work with Hibernate and I am not very sure how to solve this problem, I have 2 tables with a 1..n relationship like this: ------- TABLE_A ------- col_b (pk) col_c (pk) [other fields] ------- TABLE_B ------- col_a (pk) col_b (pk) (fk TABLE_A.col_b) col_c (fk TABLE_A.col_c) [other fields] How can I manage this with Hibernate? I do not have any idea how to declare a foreign key that would contain a part of primary key. My database schema is generated from the Hibernate model. 回答1: I

JPA 2 - Foreign key that only includes one field from a composite primary key?

折月煮酒 提交于 2019-12-05 20:27:33
I'm having trouble getting a composite primary key and foreign keys working in JPA 2/Hibernate. I'm trying to create a simple scenario with countries and provinces: Country Entity: @Entity @Table(name = "country") public class Country extends DomainObjectBase implements Serializable { @Id @Basic(optional = false) @Column(name = "code") private String code; @Basic(optional = false) @Column(name = "name") private String name; @OneToMany(cascade = CascadeType.ALL, mappedBy = "country") private List<Province> provinces; } Province Primary Key: @Embeddable public class ProvincePK implements

Using Cassandra for time series data

耗尽温柔 提交于 2019-12-05 19:25:21
I'm on my research for storing logs to Cassandra. The schema for logs would be something like this. EDIT: I've changed the schema in order to make some clarification. CREATE TABLE log_date ( userid bigint, time timeuuid, reason text, item text, price int, count int, PRIMARY KEY ((userid), time) - #1 PRIMARY KEY ((userid), time, reason, item, price, count) - #2 ); A new table will be created for the day everyday. So a table contains logs for only one day. My querying condition is as follows. Query all logs from a specific user on a specific day(date not time). So the reason, item, price, count

how to create a composite key in MySQL database

岁酱吖の 提交于 2019-12-05 18:05:45
i am working on mysql server.where i have created a table, named question . column/attributes of this table are (course,subject,year,question) i want to create a primary key(or composite key) consists of (course+subject+year). i.e. for a particular course+subject+year combination there can be only one question.there will be only one row with the combination of (course+subject+year),creation of another row won't be possible. i have done it by : primary key(course,subject,year); but it's not working.still i can create two rows with same combination of course,subject,year. can anyone tell me how

EF Composite key fluent API

笑着哭i 提交于 2019-12-05 10:27:21
I am trying to map a composite key for an entity. public class Customer { public int CustomerId { get; set; } public virtual List<CustomerImage> CustomerImages { get; set; } } And its Map: public class CustomerMap : EntityTypeConfiguration<Customer> { public CustomerMap() { HasKey(t => t.CustomerId); ToTable(DbConstants.k_CustomersImageTable); } } An Image: public class Image { public int ImageId { get; set; } } And its map: public class ImageMap : EntityTypeConfiguration<Image> { public ImageMap() { HasKey(t => t.ImageId); ToTable(DbConstants.k_ImagesTable); } } And the navigation property:

Backbone does POST instead of PUT on updates when composite key is used

ぃ、小莉子 提交于 2019-12-05 05:37:57
I'm using a composite key in my model and generate the ID based on my composite key: app.Assignment = Backbone.Model.extend({ idAttribute : [ 'personId', 'jobId' ], parse : function(resp) { resp.id = resp.personId + "_" + resp.jobId; return resp; } }); but Backbone still thinks that all instances of Assignment are new, allthough I'm setting the id in the parse method when fetching them from the API. As a result Backbone does no DELETEs and does a POST instead of PUT on updates. How can I work around this or what is the "right way" to do it? Update: Looks like replacing resp.id with this.id

How to create composite foreign key in sql server management studio 2012

☆樱花仙子☆ 提交于 2019-12-05 05:32:54
I can successfully create composite primary key in sql server management studio 2012 by selecting two columns (OrderId, CompanyId) and right click and set as primary key. But i don't know how to create foreign key on two columns(OrderId, CompanyId) in other table by using sql server management studio 2012. In Object Explorer, go to your table and select Keys > New Foreign Key from the context menu: From the dialog box that pops up, click on the Add button to create a new foreign key: Give it a meaningful name and then click on the ... button to open the Tables and Columns specification dialog

Fluent Nhibernate Composite Key Not Generating Joins For Referenced Entities

依然范特西╮ 提交于 2019-12-04 15:08:26
I have a mapping with a composite key as below: CompositeId() .KeyReference(x => x.CreatedBy, "member_key") .KeyReference(x => x.Box, "box_key"); This works fine for simple gets and inserts, however it is not generating joins with the tables mentioned in the reference where I try and use them as part of a query. So this: return _sessionFactory.GetCurrentSession().QueryOver<BoxMember>() .Where(x => x.Box.Id == boxId) .Where(x => x.Member.DeletedDate == null) .Fetch(x => x.Box).Eager .Fetch(x => x.CreatedBy).Eager .List(); Generates the following SQL: SELECT this_.member_key as member1_5_0_,

Fluent NHibernate: How to Map M:N many-to-many with composite keys on both sides

孤街浪徒 提交于 2019-12-04 14:36:58
问题 OK, so here is the problem. Its not even as crazy as the guy who wants to map m:n with different column counts in his PKs. No matter what I do or where I look there seems to be no method chain that will result in a successful mapping of this. I have tried doubling up on the Parent and Child columns, eg ParentColumn("").ParentColumn("").ChildColumn("").ChildColumn("") - didnt' think it would work and I was right. Tried just using ForeignKeyConstraintNames no luck. Still FNH is mapping one side

Entity Framework Code First One to One relationship on composite key

可紊 提交于 2019-12-04 13:46:15
Basically what I am trying to achieve is I have three tables, one parent will always have an entry in it and only one of the other two tables will be populated. The complexity that I am dealing with is that the primary key for the tables is the combination of two fields ParentTable ----------- UniqueID OwnerID [Some more fields] ChildTable1 ----------- UniqueID OwnerID [Some more fields] ChildTable2 ----------- UniqueID OwnerID [Some more fields] I was wondering if anyone has any suggestions on how best to do this through EF Code First preferably using the Fluent API. You just need to define