[hibernate-issues] [JIRA] (HHH-14105) JoinColumn for composite key requires alphabetical order

Mikhail Mayorov (JIRA) jira at hibernate.atlassian.net
Tue Jul 14 01:48:40 EDT 2020


Mikhail Mayorov ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cd931e24401890dcab39b3a ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14105?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 ) HHH-14105 ( https://hibernate.atlassian.net/browse/HHH-14105?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 ) JoinColumn for composite key requires alphabetical order ( https://hibernate.atlassian.net/browse/HHH-14105?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 )

Issue Type: Bug Assignee: Unassigned Attachments: joincolumn_demo.zip Created: 13/Jul/2020 22:48 PM Priority: Major Reporter: Mikhail Mayorov ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5cd931e24401890dcab39b3a )

***********
Description
***********

In the following example JoinColumn annotations are order sensitive:

Schema - two tables, one of them has composite key *(name, last_name)* :

create table product ( id int primary key not null , name varchar (255) not null , last_name uuid not null );
create table profile ( name varchar (255) not null , last_name uuid not null , age int not null );
alter table profile add constraint profile_pkey primary key ( name , last_name);

Entities:

@Entity
@Table
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Profile {

   @EmbeddedId
   private Id id;
   private int age;

   @Embeddable
   @NoArgsConstructor
   @AllArgsConstructor
   @Data
   public static class Id implements Serializable {
       private String name;
       private UUID lastName;
   }
}

@Entity
@Table
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Product {
   @Id
   private int id;

   @ManyToOne(fetch = FetchType.LAZY, optional = false )
   @JoinColumn(name = "name" )
   @JoinColumn(name = "last_name" )
   private Profile profile;
}

In Product entity it is impossible to specify a relation with the order of *name* and *last_name*. After debugging I've found it must be alphabetically sorted, i.e. *last_name* and *name*.
It would be better to make JoinColumn order independent or depend on natural order at worst, because the order of *name* and *last_name* is everywhere: in schema.sql, in composite key Product.Id.
Why does it require alphabetical order?

***********
Environment
***********

Spring Boot 2.3.1.RELEASE
Hibernate 5.4.17.Final
Postgres 42.2.14

****************
How to reproduce
****************

* Download joincolumn_demo.zip ( https://hibernate.atlassian.net/secure/attachment/49712/49712_joincolumn_demo.zip )
* `./mvnw test` - this run should pass
* Switch JoinColumn annotations in src/main/java/com/example/demo/Product.java the following way:
   @ManyToOne(fetch = FetchType.LAZY, optional = false )
   @JoinColumn(name = "name" )
   @JoinColumn(name = "last_name" )
   private Profile profile;

* `./mvnw test`

As a result it fails with the error:

ERROR: column "last_name" is of type uuid but expression is of type character varying
 Hint: You will need to rewrite or cast the expression

( https://hibernate.atlassian.net/browse/HHH-14105#add-comment?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14105#add-comment?atlOrigin=eyJpIjoiYzZmYzU3MjczZTMyNGM2YWIyNTc4ZDJiMTJhODlmYjkiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:cb30471 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200714/0b2d1a77/attachment.html 


More information about the hibernate-issues mailing list