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

Could not resolve repository metadata error - 500 for profile endpoints

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

@odrotbohm is already working on this.

Since Jun 8, 2021.

status: feedback-provided
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

This issue is similar to https://github.com/spring-projects/spring-data-rest/issues/1729 .

Our app works as expected most of the time but occasionally we get a 404 error for some of our API endpoints.
When we check the /profile endpoint for that repository, it returns 500 with "Could not resolve repository metadata"
It works after a restart but then fails again after a while.

We use Spring-boot-starter-data-rest : 2.2.6.RELEASE

Example UseCase :

3 Entities :

  1. Customer
  2. AppTwitter
  3. CustomerTwitter

A Customer can have multiple twitter Accounts (CustomerTwitter). One Twitter App( AppTwitter) can be used to handle multiple Customers

image

All of these entities have been exposed as repositories

Entites:

Customer.java

@Entity
public class Customer implements Serializable {

   private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column( unique = true)
    @NotBlank
    private String name;

    @ManyToOne
    @JoinColumn(foreignKey=@ForeignKey(name = "FK_CustomerToAppTwitter"),name="appTwitter_id",referencedColumnName = "twitterAppId")
    private AppTwitter appTwitter;

    @OneToMany(cascade = CascadeType.ALL,mappedBy = "customer")
    private List<CustomerTwitter> customerTwitter;

   // Getters and Setters here
}

AppTwitter.java

@Entity
public class AppTwitter implements Serializable {

   private static final long serialVersionUID = 1L;

    @Id
    private Integer twitterAppId;
    
    // Other fields specific to App

    @OneToMany(mappedBy = "appTwitter")
    private List<Customer> customer;
    
    //Getter and Setter
}

CustomerTwitter.java

@Entity
public class CustomerTwitter implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   private String twitterId
   
   // Other fields related to twitter account

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(foreignKey=@ForeignKey(name = "FK_CustomerTwitterToCustomer"), name="cust_id",referencedColumnName = "id")
  private Customer customer;
  
  // Getters and Setters
}

Repositories

CustomerRepository.java

@RepositoryRestResource
public interface CustomerRepository extends JpaRepository<Customer, Integer>{
    
}

AppTwitterRepository.java

@RepositoryRestResource
public interface AppTwitterRepository extends JpaRepository<AppTwitter, Integer>{
}

CustomerTwitterRepository.java

@RepositoryRestResource
public interface CustomerTwitterRepository extends JpaRepository<CustomerTwitter, String>{
}

Sometimes making a GET call to any one of these endpoints returns 404 error and the /profile endpoint gives 500 error with Could not resolve repository metadata

Weird thing is this happens once every 6-7 hours and almost never happens in my local environment to even figure out and debug the issue.

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.