composite-primary-key

Doctrine2 Map entities with composite foreign keys in the composite primary keys

浪子不回头ぞ 提交于 2019-12-02 05:44:57
问题 I have a model which has many tables, but in this case we only need three. The point is that the composite primary key of one is also the foreing key (composite too) and Symfony throws this exception: MappingException: It is not possible to map entity 'Your\SomethingBundle\Entity\Empleado' with a composite primary key as part of the primary key of another entity 'Your\SomethingBundle\Entity\EmpleadoHorario#empleado' . Here I explain the relationship: 1º Salon, it has a primary key ID 2º

JPA @EmbeddedId: How to update part of a composite primary key?

我是研究僧i 提交于 2019-12-02 05:32:55
问题 I have a many-to-many relationship where the link table has an additional property. Hence the link table is represented by an entity class too and called Composition . The primary key of Composition is an @Embeddable linking to the according entities, eg. 2 @ManyToOne references. It can happen that a user makes an error when selecting either of the 2 references and hence the composite primary key must be updated. However due to how JPA (hibernate) works this will of course always create a new

Why is this JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?

一曲冷凌霜 提交于 2019-12-02 04:36:36
问题 I have the following situation: (source: kawoolutions.com) JPA 2.0 mappings ( It might probably suffice to consider only the Zip and ZipId classes as this is where the error seems to come from ): @Entity @Table(name = "GeoAreas") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING) public abstract class GeoArea implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name =

Don't allow reversed composite primary key in MySQL

若如初见. 提交于 2019-12-02 02:39:22
I'm developing an application which needs to hold data about distances between two cities. I have created a distance table in the Mysql database which holds the name of the two cities and the distance between them. I have made the two town columns a composite primary key. I'd like the database to restrict the application from making duplicated reversed entries like shown on the screenshot to prevent having different distance values. What would be the best solution to solve this problem? You could create a stored procedure to insert into this table. DELIMITER $$ CREATE PROCEDURE insert_distance

JPA @EmbeddedId: How to update part of a composite primary key?

醉酒当歌 提交于 2019-12-01 23:59:39
I have a many-to-many relationship where the link table has an additional property. Hence the link table is represented by an entity class too and called Composition . The primary key of Composition is an @Embeddable linking to the according entities, eg. 2 @ManyToOne references. It can happen that a user makes an error when selecting either of the 2 references and hence the composite primary key must be updated. However due to how JPA (hibernate) works this will of course always create a new row (insert) instead of an update and the old Composition will still exist. The end result being that

Using Hibernate Get with Multi-Column Primary Key

好久不见. 提交于 2019-12-01 23:23:47
Say I have a class that looks like this: public class MyClass { @Id @Column(name = "ID") private long Id; } I can use a hibernate session to do a get or load on the class like this: MyClass a = (MyClass)session.get(MyClass.class, new Long(100)); However, assume I have a class with multiple columns as the primary key: public MyJoinClass implements Serializable { private static final long serialVersionUID = -5L; @Id @Column(name = "ID") private long id; @Id @Column(name = "EMAIL_ADDRESS_ID") private long emailAddressId; } Is it possible to use get or load with such a class? Koitoer Try to use

Why is this JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?

前提是你 提交于 2019-12-01 23:19:34
I have the following situation: (source: kawoolutions.com ) JPA 2.0 mappings ( It might probably suffice to consider only the Zip and ZipId classes as this is where the error seems to come from ): @Entity @Table(name = "GeoAreas") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING) public abstract class GeoArea implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") protected Integer id; @Column(name = "name") protected String name; ... } @Entity @Table(name =

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

隐身守侯 提交于 2019-12-01 22:15:50
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 AbstractMessage implements Message { private MessageInfo info; private int blah; @EmbeddedId public

Laravel Eloquent CANNOT Save Models with Composite Primary Keys

爷,独闯天下 提交于 2019-12-01 20:38:31
When defining composite primary keys then calling save on an instanced model, an exception is thrown. ErrorException (E_UNKNOWN) PDO::lastInsertId() expects parameter 1 to be string, array given The error occurred at line 32 $id = $query->getConnection()->getPdo()->lastInsertId($sequence); And here's the declaration of Model class ActivityAttendance extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'activity_attendance'; /** * The primary key of the table. * * @var string */ protected $primaryKey = array('activity_id', 'username'); /** * The

How to set (combine) two primary keys in a table

混江龙づ霸主 提交于 2019-12-01 17:02:06
For a small sales related application, we designed database using logical data model. Come to the stage to convert in to physical model. While creating table in SQL Server Management Studio Express, according to our logical data model, we need to combine two attributes to form unique id. Is it possible to combine two primary keys and set it? But while observing Northwind Sample, we found that in the ORDER DETAILS table, we can see two primary keys Order Id & Product Id . And according to rule table can't have two primary keys. So how it happened in Northwind? In my case how should I set two