0
package com.surya.dto;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "department")
public class Department {

    @Column
    @Id
    private int dept_id;

    @Column
    private String dept_name;

    public int getDept_id() {
        return dept_id;
    }

    public void setDept_id(int dept_id) {
        this.dept_id = dept_id;
    }

    public String getDept_name() {
        return dept_name;
    }

    public void setDept_name(String dept_name) {
        this.dept_name = dept_name;
    }

    public void sayHelloDepartment() {
        System.out.println("Hello Department");
    }
}

Is it possible to invoke method sayHelloDepartment() using Criteria API of JPA. This is a example code and I have a situation where I want to invoke a method inside a entity class from my repository classes using JPA Criteria API.

  • No, because Criteria queries are eventually translated to SQL which is then executed by the db engine, and the db engine does not know the implementation of your entities – crizzis May 26 '19 at 12:17
  • then how to get access of the id of any entity class when Is is a type safe parameter inside a custom class IdentifiableId – Harish Lalwani May 27 '19 at 09:37
  • I'm sorry, I didn't quite get your last comment, could you provide more details? Perhaps a code snippet showing what you mean? – crizzis May 27 '19 at 18:37

0 Answers0