Questions tagged [composite-primary-key]

Composite primary key is a primary key, which consists of more than one column. The column combination guarantees the uniqueness of the PK.

A Composite Primary Key is a Composite Key, which is assigned as Primary.

Primary key is a single field or the least combination of fields that uniquely identifies each record in table. When the primary key consists of more than one field, when we are talking about composite primary key. Composite or not, is the most appropriate key to be main key of reference for the table.

The primary key must not be null and must contain only unique values.

Primary keys are mandatory for every table. When choosing a primary key from the pool of candidate keys, always choose a single simple key over a composite key.

Links

984 questions
4
votes
3 answers

How do I map a n-column primary key with nHibernate

I have a table with 2 columns as PK (composite primary key). How can I map them to "Id" in hbm.xml? How can I do it with fluent nhibernate?
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
4
votes
1 answer

Choosing a good primary key for a table with a few columns which are combinedly unique

While I've been working with querying SQL databases for a while, I'm still quite the novice at actually building good tables. One thing I often struggle is with primary keys. In a table I'm creating now for logging errors on some alarm equipment, I…
Jo-Herman Haugholt
  • 462
  • 1
  • 5
  • 15
4
votes
1 answer

Does indexing on a part of a composite primary key is needed in Postgresql?

I have a (large) table with a composite primary key, composed of 5 columns (a, b, c, d, e). I'd like to efficiently select all rows having two of those columns (a + e) to a given value. In PostgreSQL, do I need an index for this? Or will the…
4
votes
1 answer

Android composite primary key?

Can anyone tell me how to declare a composite primary key in Android 1.6 which includes an autoincrement _id column? I'm not sure of the syntax. I've ended up just enforcing it in Java when I try to add values (where registrationNumber + date has to…
barry
  • 4,037
  • 6
  • 41
  • 68
4
votes
1 answer

TypeORM: @JoinTable with three columns

i got a question on typeorm and the @JoinTable- and @RelationId-Decorator. Maybe anyone can help to answer my question, give me a hint or ideally solve my problem. I am using nestjs with typeorm to provide a private api with recipes for my family…
4
votes
1 answer

Primary key does not exist in the entity in android room with composite key

The error I am getting is: error: theme_id, picture_id referenced in the primary key does not exists in the Entity. Available column names:theme_id, picture_id, image I have looked extensively online but i cannot find anything about this. This…
4
votes
2 answers

If Any field value of @EmbeddedId is null, which problem will arise?

I am fetching a problem with Hibernate @EmbeddedId. Code of my @EmbeddedId is: @Embeddable public class EnrolRegEmbededId implements Serializable { @Column(name="ENROL_NO") private String enrolNo; @Column(name="REG_NO") private String regNo; } My…
4
votes
1 answer

Eclipse IDE showing error for Composite Primary Key classes in JPA

I have an Entity class with composite PK as below: using @Embeddable and @EmbeddedId annotations. /** The primary key class for the uom_conversion database table. */ @Embeddable public class UomConversionPK implements Serializable { private…
Mahesh Kakade
  • 283
  • 1
  • 3
  • 11
4
votes
2 answers

Hibernate does not fill AUTO_INCREMENT column being part of composite PK, bug or anti-feature?

I've found a problem with Hibernate and composite key with one of its column auto incremented. I'm using MySQL and primary key composed of 2 columns, GID and LANG. GID column is set as AUTO_INCREMENT. Insert is working, hibernate inserts new row,…
Danubian Sailor
  • 1
  • 38
  • 145
  • 223
4
votes
0 answers

SQLAlchemy: Reflect and Automap Tables with Composite Primary Key

I'm trying to reflect and automap some tables in sqlalchemy that have composite primary keys from an Oracle db. When I run metadata = MetaData() metadata.reflect(bind=engine, schema='USER') Base =…
4
votes
4 answers

how to do a SELECT with a composite key?

I have a table with a composite key, and I want to do my SELECT query with that key, is there a way to put a name to the composite key or to do the query without having to add an AND let's say: SELECT * FROM MyTable WHERE PRIMARY KEY = 12345 being…
4
votes
2 answers

JPA OneToOne association where 2 entities use composite primary keys but use different column names?

We are trying to use Hibernate with a database that uses a lot of composite keys and it's been causing us a lot of headaches. Unfortunately, we can't change the schema so we have to do a lot of additional mapping betwen our fields. We are restricted…
trafalmadorian
  • 1,660
  • 1
  • 15
  • 21
4
votes
1 answer

MongoDB: find document with composite _id

I have documents in my collection with a composite _id like this: _id:{a:"", b:""} What that I want is to find the document knowing only the value of the field a. Is there some way to do this? Thanks!
betta7391
  • 103
  • 9
4
votes
2 answers

ContextErrorException: Undefined Index when using composite key for doctrine associations with Symfony 3 entities

I have two entities where each Product can have oneToMany Aspect entities associated to it. As the Products table is very large I am using bigint for it's ID, and consequently, I am trying to build a composite key for Aspect to use Product ID and a…
Bendy
  • 3,506
  • 6
  • 40
  • 71
4
votes
3 answers

How to insert a composite primary key into another table?

I have a composite primary key that I would like to insert into another table. create table courses_instructors ( courseID int foreign key references Course(C_ID) not null, instructorID int foreign key references Instructor(I_ID) not null, primary…