Questions tagged [natural-key]

A key in a database table that is used to identify entities in the business domain outside the database. It may be comprised of attributes that have intrinsic logical meaning.

The term natural key describes a key which is used for external real world identification of things and is different from a surrogate key which is not used in the business domain.

57 questions
1
vote
1 answer

Filtering by natural key?

I don't have the ids of the objects I want because they were created by bulk_create: and bulk_create doesn't return objects with ids so I need to fetch them by their natural keys. Is it possible to fetch the objects by filtering by natural key? I've…
ThePhi
  • 2,373
  • 3
  • 28
  • 38
1
vote
1 answer

Fluent NHibernate referencing entity with natural key

I'm using Fluent NHibernate automapping functionality. I've managed to get the database mappings pretty close using conventions, but there are a few things for which I need IAutoMappingOverride. In a legacy system, I have an entity class, 'Campus',…
Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52
1
vote
1 answer

Retrofit surrogate key in table with natural key in MySql?

Assume a table that uses a natural key and has a number of existing rows. What would be the easiest way to retrofit a surrogate key column and populate it with unique values using MySql? I.e. transform table employees ( social_security_no…
Erik Öjebo
  • 10,821
  • 4
  • 54
  • 75
1
vote
1 answer

What are the type of data problems that relational databases have when they are designed using natural keys (and not surrogate keys)?

I saw this comment: [applications] with the most data-related problems were those using natural keys. Source: Surrogate vs. natural/business keys I want more supporting evidence of this, as the comment left much to imagination. It suggests that…
1
vote
1 answer

Can I use an assigned, natural-key identifier while still allowing NHibernate to identify transient instances?

Object A has a one-to-many association: many object B. When I look in the database -- TableB -- I'd like to see the unique, readable string A.Name instead of having always to join or subselect on a surrogate integer identifier to see the name. I can…
Jay
  • 56,361
  • 10
  • 99
  • 123
1
vote
2 answers

Hibernate query subtyped entity by natural-id

I use Hibernate and want to query for entities by their natural identifier. However, it seems not to be possible to have natural ids on subtypes. I have two classes A and B where B extends A: class A { long id; } class B extends A { String…
Felix Feisst
  • 175
  • 10
1
vote
3 answers

Phalcon PHP: Update a primary natural key

Is there a good way to be able to update a table which has a natural key in Phalcon? Consider this table: people ------ person created_at updated_at We're going to assume that the person field is unique and is the primary key. I try to do the…
Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52
1
vote
2 answers

Email address as resource identifier in a REST API

Say my application has users, and each user is uniquely identified by their email address. In that case, it makes sense to use the natural key of email rather than using an auto incrementing ID as the primary key, which is common in most…
John Dorean
  • 3,744
  • 9
  • 51
  • 82
1
vote
1 answer

Hibernate: NaturalId with inheritance

I have following Entities (short version): GroupOfStudents: @Entity @Table(name = "group_of_students") @Inheritance(strategy = InheritanceType.JOINED) public abstract class AGroupOfStudents extends AModel { } Centuria: @Entity @Table(name =…
jansepke
  • 1,933
  • 2
  • 18
  • 30
1
vote
1 answer

Must Django ManyToManyField association tables have a surrogate key?

I'm mapping an existing database structure into Django models. I have a many-to-many structure where the association table is natural-keyed: CREATE TABLE foo (id INTEGER PRIMARY KEY); CREATE TABLE bar (id INTEGER PRIMARY KEY); CREATE TABLE foo2bar…
1
vote
2 answers

Unable to use natural keys in django foreign key serialization

So the thing is I have a class which has a foreign key. This is my code class Proxy(models.Model): class Meta: db_table = 'Proxy' equipment = models.ForeignKey('Equipment', primary_key=True) pop = models.ForeignKey('Pop') Now, as…
Agniva De Sarker
  • 778
  • 2
  • 12
  • 22
0
votes
0 answers

Django Natural Keys Unable to Load For Some Models

I have a project with several models All of which I am implementing natural keys. Most of these are working but there is one model (so far) that refuses to load when I export using natural keys. NOTE: If I don't use natural keys when exporting it…
Alex
  • 1,891
  • 3
  • 23
  • 39
0
votes
1 answer

Rest with natural keys: Can a 201 Created response to HTTP PUT include a Location header that differs from the request URI?

I am designing an API endpoint that uses natural keys as resource identifiers. PUT /api/thing/key GET /api/thing/key etc. My service exposes an Update(...) operation that would result in an SQL UPDATE query that could change this key i.e. void…
Samuel Danielson
  • 5,231
  • 3
  • 35
  • 37
0
votes
2 answers

Unique constraints on their own or as a primary key?

Is there any benefit to using a table schema like this: CREATE TABLE review ( review_id SERIAL PRIMARY KEY, account_id INT REFERENCES account(account_id) NOT NULL, product_id INT REFERENCES product(product_id) NOT NULL, rating…
Matt
  • 463
  • 4
  • 14
0
votes
1 answer

Hibernate: bug when mapping a reference to an alternative/natural key column of a sub table?

The original question stems from this question: Why is this JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools? As you can see this constellation also freaks out the Eclipse Dali JPA validator. The JPA spec seems to allow this as seen here…
Kawu
  • 13,647
  • 34
  • 123
  • 195