Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Inconsistent handling of polymorphic entities with only a repository for the root entity type

Aperta
#2,170 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@odrotbohm ci sta già lavorando.

Dal 31/8/2022.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

type: bug

If I define a hierarchy of entities, and a polymorphic repository only for the root entity, descendants of the root entity are included under the management of the polymorphic repository only if it exists at least another entity (with a repository) with a linkable association to the specific subclass.

For example, given the following:

@Entity
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = STRING)
public abstract class Address {
  ...
}

@Entity
@DiscriminatorValue("Residential")
public class ResidentialAddress extends Address {
}

@Entity
@DiscriminatorValue("Business")
public class BusinessAddress extends Address {
}

@Entity
public class Person {
  ...
  @OneToOne(fetch = FetchType.LAZY)
  private ResidentialAddress residentialAddress;
  ...
}

@RepositoryRestResource(path = "addresses", collectionResourceRel = "addresses")
public interface AddressRepository extends JpaRepository<Address, Long> {
}

@RepositoryRestResource(path = "people", collectionResourceRel = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {
}

then, ResidentialAddress will be handled by the AddressRepository and its rels and href will reflect the ones specified on the AddressRepository.
The BusinessAddress, instead, while still returned by the AddressRepository, it will have rels and href generated using the Evo Inflector, which returns an invalid href for the links (businessAddress) which is not mapped and you will get a 500 if you tried to retrieve it under the link specified URL.

The following is an example of the payload returned by querying the collection resource '/addresses':

{
  "_embedded" : {
    "addresses" : [ {
      "label" : "Home",
      "address" : "The Elves",
      "_links" : {
        "self" : {
          "href" : "http://localhost/addresses/1"
        },
        "address" : {
          "href" : "http://localhost/addresses/1"
        }
      }
    } ],
    "businessAddresses" : [ {
      "label" : "Holiday",
      "address" : null,
      "_links" : {
        "self" : {
          "href" : "http://localhost/businessAddress/2"
        },
        "businessAddress" : {
          "href" : "http://localhost/businessAddress/2"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost/addresses"
    },
    "profile" : {
      "href" : "http://localhost/profile/addresses"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 2,
    "totalPages" : 1,
    "number" : 0
  }
}

My expectation is that entities in a hierarchy should be handled by their specific repository or by the next specified ancestor's repository.

This is a demo project demonstrating the issue: demo.zip

Lingua principale
Java
Stelle
957
Fork
570
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-data-rest

Tutte le issue di spring-projects/spring-data-rest

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.