composite-key

Hibernate / JPA many to many relationship through a join table and a composite key, Unique Constraint issue

南楼画角 提交于 2019-12-04 08:18:00
So I asked this question yesterday, but the goal posts have changed and the question is different: Hibernate / JPA Collection of Elements with Many to Many relationship? I want to know if it's possible to create entities that will model my required relationship so that Hibernate will create my schema when I fire up my application. The relationship I want looks like this: 1 http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/417593_10150594114269218_505554217_8657377_1475865815_n.jpg The thing is that the Join table can actually contain rows that don't link to any Elements. The structure represents

Query using composite keys, other than Row Key in Cassandra

故事扮演 提交于 2019-12-04 04:47:09
I want to query data filtering by composite keys other than Row Key in CQL3. These are my queries: CREATE TABLE grades (id int, date timestamp, subject text, status text, PRIMARY KEY (id, subject, status, date) ); When I try and access the data, SELECT * FROM grades where id = 1098; //works fine SELECT * FROM grades where subject = 'English' ALLOW FILTERING; //works fine SELECT * FROM grades where status = 'Active' ALLOW FILTERING; //gives an error Bad Request: PRIMARY KEY part status cannot be restricted (preceding part subject is either not restricted or by a non-EQ relation) Just to

How to make a composite key to be unique?

瘦欲@ 提交于 2019-12-04 04:06:48
I am making a database of students in one school.Here is what I have so far: If you don't like reading jump to the "In short" part The problem is that I'm not happy with this design. I want the combination of grade , subgrade and id_class to be unique and to serve as a primary key for the students table. I can remove the student_id and make a composite key from the 3 but I don't want that either. Maybe I should make another table lets say combination_id where grade , subgrade and id_class are foreign keys and there is one extra column comb_id that serves as ID for the table. And all the

Validation rule for a composite unique index (non-primary)

这一生的挚爱 提交于 2019-12-04 04:06:35
I am sure I am not the first who has composite unique keys in tables and who wants to validate them. I do not want to invent the bicycle so I ask here first. I have several tables that have 'id' columns as primary keys and two other columns as unique composite keys. It would be nice to have a validation rule to check that the submitted entry is unique and display a validation error if it is not. In Cakephp it could be done by a custom validation rule. I am pretty sure somebody has created such method already. Ideally it would be a method in app_model.php that could be used by different models.

Hibernate foreign key with a part of composite primary key

谁说我不能喝 提交于 2019-12-04 03:36:39
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. I have found two solutions to this problem. The first one is rather a workaround and is not so neat as the

Duplicate columns when using EmbeddedId with a ManyToOne mapping with Ebean

≡放荡痞女 提交于 2019-12-03 23:34:37
I have a model called "EventCheckin" which has a ManyToOne mapping to an "Event" and a "User". The PrimaryKey of the "EventCheckin" table is the id of the user and the id of the event. I'm trying to represent this using an "EmbeddedId" in my EventCheckin model but when I attempt to save an EventCheckin it tries to put the user_id and event_id values into the table twice which obviously fails: Caused by: org.h2.jdbc.JdbcSQLException: Duplicate column name "USER_ID"; SQL statement: insert into eventCheckin (event_id, user_id, latitude, longitude, user_id, event _id) values (?,?,?,?,?,?) [42121

EF 4.1 EntityType has no key - composite

风格不统一 提交于 2019-12-03 12:57:20
I have just upgraded to the latest EF 4.1 code-first using NuGet and now I am receiving an error regarding my mapping. I have this class public class UserApplication { [Key, Column(Order = 0)] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int UserId { get; set; } [Key, Column(Order = 1)] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int ApplicationId { get; set; } [ForeignKey("ApplicationId")] public virtual Application Application { get; set; } public DateTime SubscribedDate { get; set; } } And I am getting this error: System.Data.Edm.EdmEntityType: : EntityType

Oracle composite primary key / foreign key question

冷暖自知 提交于 2019-12-03 11:19:39
I have a composite primary key in 1 table in oracle. I want to create a foreign key for one table entry in my second table that references the composite primary key in the first table. I am getting the error ORA-02256. Any thoughts on how I can enter this? CREATE TABLE groupspersonx ( personid number, groupid number, CONSTRAINT pk_persongroupid PRIMARY KEY(personid, groupid) ); CREATE TABLE restrictedgroups ( groupid number, name varchar2(50), dateadded date, since date, notes varchar2(1024), CONSTRAINT pk_groupid PRIMARY KEY(groupid), CONSTRAINT fk_persongroup FOREIGN KEY(groupid) REFERENCES

Foreign key mapping inside Embeddable class

人盡茶涼 提交于 2019-12-03 11:06:56
I am using eclipselink for JPA . I have an entity, which has a composite key fabricated out of two fields. Following is my Embeddable primary key class' fields(members). @Embeddable public class LeavePK { @ManyToOne(optional = false) @JoinColumn(name = "staffId", nullable = false) private Staff staff; @Temporal(TemporalType.TIMESTAMP) private Calendar date; //setters and getters } My entity is going to hold leave data related to a staff, so I am trying to combine staff object and leave date to produce composite key. Apart from my logic, it is not allowing me to have a foreign key mapping

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

99封情书 提交于 2019-12-03 10:13:41
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 to a single key. public partial class M2M2ParentAMap : ClassMap<M2M2ParentA> { public M2M2ParentAMap()