composite-primary-key

JPA Query returning nulls - Composite Key with null column

旧街凉风 提交于 2020-01-03 08:25:19
问题 I have a legacy database (Cobol files actually) that I am accessing using a proprietary JDBC driver with Hibernate/JPA. The Entity has a composite primary key with 2 columns: CODE and SITE . In the legacy data there are records for the same CODE that can have either a specific value for SITE , or there can be a record with NULL in the SITE column which represents 'All Sites'. The theory of this file is, if you cannot find the CODE for your specific SITE then you lookup the record with NULL in

Entity Framework and MVC Scaffolding with Composite Primary Keys

别等时光非礼了梦想. 提交于 2020-01-02 09:29:34
问题 I'm curious about how Entity Framework and MVC scaffolding handle primary keys. When I create a controller in an MVC3 project and choose the scaffolding template of 'Controller with read/write actions and views, using Entity Framework' and specify my model a controller is generated that uses one primary key. My entity has 2 keys which are needed to pull data correctly. I made the necessary adjustments manually but I wanted to make sure I understand this properly before moving forward. My

How to set the column order of a composite primary key using JPA/Hibernate

試著忘記壹切 提交于 2019-12-31 01:56:48
问题 I'm having trouble with the ordering of the columns in my composite primary key. I have a table that contains the following: @Embeddable public class MessageInfo implements Serializable { private byte loc; private long epochtime; @Column(name = "loc") public byte getLoc() { return loc; } @Column(name = "epochtime") public long getEpochtime() { return epochtime; } } It is used in this mapping: @MappedSuperclass @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class

“No mapped field” when using partial query and composite keys in Doctrine2

喜你入骨 提交于 2019-12-30 17:38:44
问题 I have two models called Person and Tag . One Person has many Tags, and the Tag primary key is a composite key of person_id and tag ( Person $person and $tag in Doctrine2). There is a data field ( BLOB ) in the Tag model with a lot of data. I am setting up a query that does not require the data from that field, so I want to set up a query that does not retrieve that field. I tried with the following query: SELECT c, PARTIAL t.{tag} FROM Contact c LEFT JOIN c.tags Here, I get the somewhat

“No mapped field” when using partial query and composite keys in Doctrine2

天涯浪子 提交于 2019-12-30 17:38:33
问题 I have two models called Person and Tag . One Person has many Tags, and the Tag primary key is a composite key of person_id and tag ( Person $person and $tag in Doctrine2). There is a data field ( BLOB ) in the Tag model with a lot of data. I am setting up a query that does not require the data from that field, so I want to set up a query that does not retrieve that field. I tried with the following query: SELECT c, PARTIAL t.{tag} FROM Contact c LEFT JOIN c.tags Here, I get the somewhat

Composite Key functions in Hyperledger

感情迁移 提交于 2019-12-30 11:15:19
问题 I need to implement composite keys in hyperledger so that I could have a unique key based on the attributes put into the ledger. The function CreateCompositeKey(objectType string, attributes []string)(string,error) takes in objectType and attributes string. I couldnt find any examples of this online, how are the relevant attributes to be made into the composite key passed and in what way is the output given? So the way Composite keys should be used is make a key first and then push it to the

IN clause with a composite primary key in JPA criteria

坚强是说给别人听的谎言 提交于 2019-12-30 06:27:10
问题 I have a table named group_table in MySQL with only two columns user_group_id and group_id (both of them are of type VARCHAR ). Both of these columns together form a composite primary key. I need to execute a statement using a sub-select IN() to select rows based on a list of values passed to the query. @Override @SuppressWarnings("unchecked") public List<GroupTable> getList(List<GroupTable> list) { CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<GroupTable>

PostgreSQL composite primary key

流过昼夜 提交于 2019-12-28 03:45:17
问题 In MySQL, when I create a composite primary key, say with columns X, Y, Z , then all three columns become indexes automatically. Does the same happen for Postgres? 回答1: If you create a composite primary key, on (x, y, z) , PostgreSQL implements this with the help of one UNIQUE multi-column btree index on (x, y, z) . In addition, all three columns are NOT NULL (implicitly), which is the main difference between a PRIMARY KEY and a UNIQUE INDEX . Besides obvious restrictions on your data, the

how to use two columns as primary key in hibernate

戏子无情 提交于 2019-12-25 08:30:07
问题 I have a table with five columns. The two columns, together, make up the primary key of my table. I'm trying to instantiate an Entity class that corresponds to that table using hibernate. The problem is how do I tell hiberante that the primary key is not just a single field of the class but two. I don't want hiberante to create the database schema for me as I have already crated it with all the necessary primary key settings. I have read about the composite-key but it think that is not

How do I create a composite primary key in hibernate within the hbm.xml file

拟墨画扇 提交于 2019-12-25 04:27:15
问题 I have the following three simple classes. How do I go about mapping the Rating class and more specifically its composite key in my Rating.hbm.xml file? I'm currently getting quite lost in the hibernate documentation (5.1.2.1. Composite identifiers) Each rating can have one book and one user making that specific rating. Each user can make many ratings. Each book can have many ratings. Classes Rating class public class Rating { private User user; private Book book; private int rating; private