Skip to content

Could not resolve repository metadata error - 500 for profile endpoints #2014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dharshanah opened this issue May 17, 2021 · 4 comments
Open
Assignees
Labels
status: feedback-provided Feedback has been provided

Comments

@dharshanah
Copy link

This issue is similar to #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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 17, 2021
@mp911de
Copy link
Member

mp911de commented Jun 7, 2021

Can you enable debug logging or provide a stack trace by other means so that we understand what's causing the issue?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jun 7, 2021
@dharshanah
Copy link
Author

Hi. Thank you for replying @mp911de . I have now enabled debug logging and will attach the stacktrace when the error happens again. For now, I am attaching the normal error logs sdr_logs.txt

As of now, there are no users using this instance of the application. I have a healthcheck script running every 10 mins which tries to hit the profile endpoint of Customer, AppTwitter and CustomerTwitter . Attached file contains the stacktrace when the profile endpoint failed for Customer and AppTwitter.

I will get back to you soon with the debug logs as and when I notice an error.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 7, 2021
@odrotbohm
Copy link
Member

I am afraid I'm not really able to get to the bottom of this without some project to play with. It's not clear what the request looks like for the stack trace. What puzzles me is that apparently a RootResourceInformation is supposed to be resolved but none of the controller methods in the ProfileController actually take one. This seems to indicate that the request that caused that stack trace did not hit /profile/… but a different URL.

What also generally looks problematic is that literally every entity is backed by a repository including bi-directional relationships between those entities. It's very easy to get these wrong, e.g. by not properly updating the back-reference in the setter for a related entity and thus, depending on which side you're updating, you might see the opposite side not updating properly. That in turn might then cause 404s for instances that failed to be created due to the mapping issues. We generally recommend to avoid bi-directional relationships and proper aggregate modeling. Not because SD REST doesn't work in a scenario like described above, but the likelihood of user code missing a tiny piece and that causing the program to fail. Another aspect is API purity. If you model bi-directional aggregate relationships, which side do you update references from?

@odrotbohm odrotbohm added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jun 8, 2021
@dharshanah
Copy link
Author

Thank you @odrotbohm for your response. I will create a sample project and will update soon.

As I mentioned earlier, this application is in an instance which is not used right now (except for the health checks hitting the profile endpoints). I have attached the debug logs for the same where the /profile/{entity} returns error
debug_logs.txt

Regarding bi-directional relationships, point noted. The use-case required that all of these entities to be backed by repositories. But I understand that this could be a problem. I will see if I can model it better.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

4 participants