spring-projects / spring-projects/spring-data-rest

Subtyped Entity produces invalid (404) "self" reference [DATAREST-821]

Open
#1,197 4 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Christian Bongiorno opened DATAREST-821 and commented

I have and entity with subclasses representing different contact methods. For example:
Phone, address, twitter, etc.

The problems is that when I fetch a specific resource, the "self" reference is wrong. Following it produces a 404. See screen shot.

GET: http://localhost:8080/hal/contactMethods/1

{
    "method": "PHONE",
    "country": "USA",
    "format": "([0-9])([0-9]{3})([0-9]{3})([0-9]{4}); $1 ($2) $3-$4",
    "extension": null,
    "number": "17778889999",
    "_links": {
        "self": {
            "href": "http://localhost:8080/hal/phoneMethod/1"
        },
        "af:phoneMethod": {
            "href": "http://localhost:8080/hal/phoneMethod/1"
        },
        "curies": [
            {
                "href": "/custom/docs/{rel}.txt",
                "name": "af",
                "templated": true
            }
        ]
   }

Here are the entities:


@Entity
@Getter
@EqualsAndHashCode
@ToString
@NoArgsConstructor
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="method")
public class ContactMethod {

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private Long id;


    private String method;

}
@Entity
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
@NoArgsConstructor
@AllArgsConstructor
public abstract class AddressMethod extends ContactMethod{

    private String country;

}
@Entity
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
@NoArgsConstructor
@AllArgsConstructor
@DiscriminatorValue("USA_ADDRESS")
public class USAAddressMethod extends AddressMethod {

    private String attention;

    private Integer buildingNumber;

    @NotNull
    private String streetName;

    private String suite;

    @NotNull
    @Enumerated(EnumType.STRING)
    private State state;

    @NotNull
    private String postalCode;
}
@Entity
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
@NoArgsConstructor
@AllArgsConstructor
@DiscriminatorValue("PHONE")
public class PhoneMethod extends ContactMethod {

    @Length(min = 3, max = 3)
    private String country;

    @NotNull
    private String format;

    private String extension;

    // must include +(cc)
    @Length(min = 12, max = 16)
    private String number;


}

Affects: 2.4.4 (Gosling SR4), 2.5.1 (Hopper SR1)

Attachments:

1 votes, 3 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.