Skip to content
Advertisement

Create custom finder with spring

I trying to implement a database with a many-to-many relationship.The database has been built, now we need queries to it. I’m using this article as an example: https://www.bezkoder.com/jpa-many-to-many/. When I create custom finder in Repository – server crushes at running.

I have two Entity: MassageEntity and RstringsEntity. I’m trying to create a method List<MasageEntity> findMasageEntitiesByRstringsEntitiesId(Long string_id);. Without that method server starts.

This is what the error looks like.

JavaScript

Now i show some code.

RstringEntity.java

JavaScript

MassageEntity.java

JavaScript

strings_repo.java

JavaScript

massage_repo.java

JavaScript

I don’t see the point in showing the controller, since the error occurs elsewhere.

What’s I doing wrong? Maybe I need some settings or dependencies? Or I can solve the problem in a different way?

Advertisement

Answer

Your problem is the name of the query method: findMasageEntitiesByRstringsEntitiesId(Long. You need to use the field name from your entity class, not the class name.

I would try findMasageEntitiesByStringsId(Long.... (It’s also a bit confusing that you’ve given the variable one name and the getter method another, not sure if JPA will like that.)

The other methods which returns a list also suffer from the same problem.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement