darrachequesne / spring-data-jpa-datatables

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

Plugin indeed doesn't work with @Transient properties for @Entity #80

Closed kkaun closed 4 years ago

kkaun commented 5 years ago

Hi, I have an issue similar to this one: adding @Transient even to @Entity field of simple type leads to DT warning/error : DataTables warning: table id=users - java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [placesNum] on this ManagedType [com.kirak.domain.User] , afer which DT renders no data AKA "No matching records found".

My sample field:

    @JsonInclude //Tried to comment this
    @JsonProperty("ownPlacesNum") //Tried to comment this
    @JsonView(DataTablesOutput.View.class)
    @Transient
    private Integer ownPlacesNum;

I tried to play with getters and their annotations - still the same. Though I really don't want to get rid of this awesome extension and have some workaround, this issue brings a little headache as it becomes nearly impossible to ignore any kinds of entities' properties. Hope it may remind to come up with something. Thanks.

RomanKurbanov commented 5 years ago

Does it work outside of DataTables environment? If you send a GET request to your entity's api, does the transient field appear?

kkaun commented 5 years ago

Yup, tried that just few moments ago and received fully valid JSON, including transient fields :(

RomanKurbanov commented 5 years ago

I can only offer using @Formula annotation for now, see if that fits your use case.

kkaun commented 5 years ago

@iSosnitsky, thanks, I'll try it!

darrachequesne commented 5 years ago

It think you need to add:

{
    "data": "ownPlacesNum",
    "orderable": false,
    "searchable": false
}

So that the column is not used as a filter.

sebasira commented 5 years ago

I was having the same issue as @kkaun with the @darrachequesne proposal I'm able to render the DataTable.

I can live without the ordering and searching of that column but it would be great if we could

darrachequesne commented 4 years ago

Closed due to inactivity, please reopen if needed.