composite-primary-key

Spring Data JPA - create @Composite key for the three tables

坚强是说给别人听的谎言 提交于 2019-11-30 10:39:23
I am extending my question from here: Define CompositeKey with three tables using JPA/Hibernate? . In this example, I am looking to create Composite key to create unique combination of PRODUCT_ID, CATEGORY_ID, STOCK_ID. I developed below code, but not sure on how to save the records into DB. Stock.java @Entity public class Stock implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "STOCK_ID", unique = true, nullable = false) private Integer stockId; @Column(name = "STOCK_CODE", unique = true, nullable = false, length

Hibernate n:m extractHashCode throws NullPointerException

ε祈祈猫儿з 提交于 2019-11-30 09:16:19
问题 I get the following exception while inserting an object with hibernate. Reading from the database works like a charm. I use MySQL 5.5 as database provider and hibernate 3.6.5 . I have the following database schema: cell(id,cellid,lac,mcc,mnc,insertTime) location(id,latitude,longitude,altitude,accuracy,heading,hdop,vdop,pdop,insertTime) cellatlocation(servingCell,neighbourCell,location,signalStrength,insertTime) where id in cell and location are primary keys and servingCell,neighbourCell and

NULL value in multi-column primary key

橙三吉。 提交于 2019-11-30 07:48:19
I've got a table with several columns making up the primary key. The nature of the data stored allows some of these fields to have NULL values. I have designed my table as such: CREATE TABLE `test` ( `Field1` SMALLINT(5) UNSIGNED NOT NULL, `Field2` DECIMAL(5,2) UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (`Field1`, `Field2`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB; However, when I run describe test it shows like this: || *Field* || *Type* || *Null* || *Key* || *Default* || *Extra* || Field1 || smallint(5) unsigned || NO || PRI || || || Field2 || decimal(5,2) unsigned || NO || PRI || 0.00 ||

How to make Primary key Auto increment while using Composite Primary keys in Room persistent library?

丶灬走出姿态 提交于 2019-11-30 06:31:16
问题 I am using Room persistent library. I have requirement to add two primary keys in one table and one of the primary key should be auto increment. I don't know exact syntax to achieve this. Below is my Model class: @Entity(tableName = "newsPapers", primaryKeys = {"news_paper_id","news_paper_name"}) public class SelectNewsModel { private int news_paper_id; @ColumnInfo(name = "image_url") private String imageUrl; @ColumnInfo(name = "news_paper_name") private String newsPaperName; } I want to make

SQLAlchemy joins with composite foreign keys (with flask-sqlalchemy)

倖福魔咒の 提交于 2019-11-30 04:22:35
问题 I'm trying to understand how to do joins with composite foreign keys on SQLAlchemy and my attempts to do this are failing. I have the following model classes on my toy model (I'm using Flask-SQLAlchemy, but I'm not sure this has anything to do with the problem): # coding=utf-8 from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) class Asset(db.Model): __tablename__ =

What are the pros and cons of using multi column primary keys?

岁酱吖の 提交于 2019-11-30 02:04:43
I would like to see an example of: When this is appropriate When this is not appropriate Is there a time when the choice of database would make a difference to the above examples? This really seems to be a question about surrogate keys, which are always either an auto-incrementing number or GUID and hence a single column, vs. natural keys, which often require multiple pieces of information in order to be truly unique. If you are able to have a natural key that is only one column, then the point is obviously moot anyway. Some people will insist on only using one or the other. Spend sufficient

alter composite primary key in cassandra CQL 3.0

℡╲_俬逩灬. 提交于 2019-11-29 16:04:41
问题 I'm in a situation where I need to change the the composite primary key as follows: Old Primary Key: (id, source, attribute_name, updated_at); New Primary Key I want: (source, id, attribute_name, updated_at); I issued the following (mysql like) command: ALTER TABLE general_trend_table DROP PRIMARY KEY, ADD PRIMARY KEY(source, id, attribute_name, updated_at); I got the following error: Bad Request: line 1:38 no viable alternative at input 'PRIMARY' any idea how to get around this problem? more

Spring Data JPA - create @Composite key for the three tables

北城以北 提交于 2019-11-29 15:53:59
问题 I am extending my question from here: Define CompositeKey with three tables using JPA/Hibernate?. In this example, I am looking to create Composite key to create unique combination of PRODUCT_ID, CATEGORY_ID, STOCK_ID. I developed below code, but not sure on how to save the records into DB. Stock.java @Entity public class Stock implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "STOCK_ID", unique = true, nullable

Referencing a composite primary key

冷暖自知 提交于 2019-11-29 13:08:11
问题 I have two tables, with each table having a composite primary key. One attribute is in both composite primary keys. How am i supposed to reference the common attribute?? Do i just reference it as a FK in both tables as below? The cust_id and flight_id below are each part of the composite key as well and reference primary keys in other tables. (Ignore the third attribute in the erd for the br_flight table as I choose to use a composite key in the end). CREATE TABLE BOOKING_REFERENCE (

NULL value in multi-column primary key

。_饼干妹妹 提交于 2019-11-29 10:31:34
问题 I've got a table with several columns making up the primary key. The nature of the data stored allows some of these fields to have NULL values. I have designed my table as such: CREATE TABLE `test` ( `Field1` SMALLINT(5) UNSIGNED NOT NULL, `Field2` DECIMAL(5,2) UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (`Field1`, `Field2`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB; However, when I run describe test it shows like this: || *Field* || *Type* || *Null* || *Key* || *Default* || *Extra* || Field1 |