0

I have the following spring-data-jpa entity:

@Entity(name = "absenceDays")
@Table
public final class MyTable {

    @EmbeddedId
    private MyId myId;

    @Column(nullable = false)
    private Long anotherId;

}

further, this is the @Embeddable entity used above:

public final class MyId implements Serializable {

    @Column(updatable = false, nullable = false)
    private Long id;

    @Column(updatable = false, nullable = false)
    private LocalDate date;

 }

I have couple of questions?

  1. Are tables already indexed with their primary keys? It seems to be implementation specific, as discussed here When should I use primary key or index?
  2. How should I index my table with the composite id using the JPA 2.1 @Index annotation, if I need to index my table?

My DB of choice will be AWS RDS with MySQL InnoDB dialect.

Rajan Prasad
  • 1,582
  • 1
  • 16
  • 33
  • 2
    why don't you check the generated schema? In any case: do not use JPAs schema generation for setting up or maintaining your production database schema. Use a tool intended for that purpose like Flyway or Liquibase. – Jens Schauder Nov 25 '19 at 05:53

1 Answers1

0

Since you tagged the Question [mysql], I will address it from that point of view.

In MySQL the PRIMARY KEY is always UNIQUE and a KEY (aka INDEX). In the case of ENGINE=InnoDB, it is also "clustered" with the data. This makes fetching a row, given the PK, very fast.

To ask questions related to MySQL, it is best to dig below the 3rd party interface (Spring, in your case) to get to the MySQL (or MariaDB or Aurora) info, such as CREATE TABLE and SELECT....

I could probably answer your Q2 with the above info.

Rick James
  • 135,179
  • 13
  • 127
  • 222