0

I have a List of APIObjects List<APIObjects> apiObjectList as an Input to my API (through HTTP-Post), I need to check all the parameters within this Object exists in my Database

DatabaseObject.java

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "my_table")
public class DatabaseObject {

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

    @Column(name = "name")
    String name;

    @Column(name = "group_id")
    String groupId;

    @Column(name = "artifact_id")
    String artifactId;

    @Column(name = "version")
    String version;
 }

APIObject.java

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class APIObject{
    private String groupId;
    private String artifactId;
    private String version;
}

In my Repository Interface i have a method like this

List<DatabaseObject> findByGroupIdAndArtifactIdAndVersionIn (List<APIobject> apiList);

But i get this exception

Caused by: java.lang.IllegalArgumentException: No parameter available for part artifactId SIMPLE_PROPERTY (1): [Is, Equals].

How to write a Spring-data-JPA method for this ? All the three parameters should match (groupid, artifactid and version)

2 Answers 2

1

If you want to create a query from method names, you should change the repository method:

List<DatabaseObject> findByGroupIdAndArtifactIdAndVersion(String groupId, String artifactId, String version);

Or with In keyword:

List<DatabaseObject> findByAPIobjectIn(Collection<APIObject> apis)

See Query Creation for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The groupId, artifactId and version is in a list. Do you mean to say that I need to iterate that list and start firing queries individually ? Suppose if i get a big list, individual query firing seems to be a costly solution
0

Try using Query by Example technique. In your case the solution may look like this:

DatabaseObject dbObject = new DatabaseObject(apiObject.getGroupId(), ...);
Iterable<DatabaseObject> dbObjects = DatabaseObjectRepository.findAll(Example.of(dbObject));

1 Comment

How to give a list of APIObject and ensure all the groupid-artifactid-version is there in the table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.