darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
448 stars 172 forks source link

Unable to locate Attribute #129

Closed EpsilonKu closed 3 years ago

EpsilonKu commented 3 years ago

The problem is DataTableRepository return error on dataTableOutput.

DataTablesOutput(
draw=1, 
recordsTotal=4, 
recordsFiltered=0, 
data=[], 
searchPanes=null, 
error=java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [name] on this ManagedType [kz.bitlab.robygroup.sppmid.core.models.entities.BaseEntity]) 

My Entity

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@SequenceGenerator(
        name = "seq",
        sequenceName = "s_main_processes",
        initialValue = 1,
        allocationSize = 1
)
public class MainProcess extends BaseEntity {

    @Column(name = "parent_id")
    private Long parentId;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "organization_id")
    private Organizations organization;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "gos_organ_id")
    private Organizations gosOrganization;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "department_id")
    private Departments department;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id")
    private Users author;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "currency_id")
    private Currencies currency;

    @Column(name = "limit_value")
    private int limitValue;

    @Column(name = "initial_limit_value")
    private int initialLimitValue;

    @Column(name = "first_year")
    private int firstYear;

    @Column(name = "second_year")
    private int secondYear;

    @Column(name = "third_year")
    private int thirdYear;

    @Column(name = "status")
    private int status;

    @Column(name = "status_text")
    private String statusText;

    @Column(name = "stage")
    private int stage;

    @Column(name = "stage_role")
    private String stageRole;

    @Column(name = "stage_name")
    private String stageName;

    @Column(name = "is_declined")
    private int isDeclined;

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

    @Column(name = "is_combined")
    private int isCombined;

    @Column(name = "is_uncombinable")
    private int isUncombinable;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "process_mid_perfomers",
            joinColumns = @JoinColumn(name = "process_id"),
            inverseJoinColumns = @JoinColumn(name = "user_id")
    )
    private Set<Users> midPerformers;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "process_go_perfomers",
            joinColumns = @JoinColumn(name = "process_id"),
            inverseJoinColumns = @JoinColumn(name = "user_id")
    )
    private Set<Users> goPerformers;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "process_section_datas",
            joinColumns = @JoinColumn(name = "process_id"),
            inverseJoinColumns = @JoinColumn(name = "section_data_id")
    )
    private Set<SectionData> sectionData;

}

Base Entity

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Data
public class BaseEntity implements Serializable {

    @Id
    @GeneratedValue(generator = "seq")
    @Column(updatable = false, nullable = false)
    private Long id;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_at", nullable = false, updatable = false)
    private Date createdAt;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "updated_at")
    private Date updatedAt;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "deleted_at")
    private Date deletedAt;

    @PrePersist
    public void prePersist(){
        this.createdAt = new Date();
    }

    @PreUpdate
    public void preUpdate(){
        this.updatedAt = new Date();
    }

    @PreRemove
    public void preDelete(){
        this.deletedAt = new Date();
    }
}
darrachequesne commented 3 years ago

It seems there is no name attribute on your entity. Did you declare one on the client-side?

var table = $('table#sample').DataTable({
    ajax : '/data/users',
    serverSide: true,
    dom: 'Pfrtip',
    columns : [{
      data : 'name'
    }]
  });
EpsilonKu commented 3 years ago

Thanks, I used default value. it works, now