Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new fields on DTO #701

Closed
cemo opened this issue Aug 17, 2020 · 6 comments
Closed

Adding new fields on DTO #701

cemo opened this issue Aug 17, 2020 · 6 comments

Comments

@cemo
Copy link
Contributor

cemo commented Aug 17, 2020

@Introspected
public class BookDTO {

    private String title;
    private int pages;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }
}

The DTO should include properties that match the property names you wish to project on (in this case title and pages). If any properties do not match then a compilation error will occur.

I would like to add a new computed column from database. When I check necessary implementation it checks necessary field on persistent entity. How this field is not available. What is the correct approach to solve this?

    @Nullable
    @Override
    public Object read(@NonNull S object, @NonNull String name) throws ConversionErrorException {
        RuntimePersistentProperty<T> pp = persistentEntity.getPropertyByName(name);
        if (pp == null) {
            throw new DataAccessException("DTO projection defines a property [" + name + "] that doesn't exist on root entity: " + persistentEntity.getName());
        } else {
            return read(object, pp);
        }
    }
@graemerocher
Copy link
Contributor

yeah I think we need to make this check more lenient and fallback to trying to read the column. Only issue is with that is the naming strategy to use to convert property names to column names

@cemo
Copy link
Contributor Author

cemo commented Aug 17, 2020

Would you please guide me? I may contribute this as well.

@cemo
Copy link
Contributor Author

cemo commented Aug 17, 2020

Only issue is with that is the naming strategy to use to convert property names to column names

Using persistentEntity's strategy maybe?

@graemerocher
Copy link
Contributor

Already fixed by 3d2377c

@zepfred
Copy link

zepfred commented Jan 28, 2021

Hi @graemerocher, this new feature doesn't work for collections of elements. I could open an issue for this request if you think is viable.

@graemerocher
Copy link
Contributor

@zepfred sure go ahead and open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants