question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter to attributes by abstract class not working

See original GitHub issue

Description

I create a abstract class to convert a attribute status to a ENUM in the constructor and try to apply a equals filter, but I got a The attribute with the name 'status' couldn't be found on the view type 'AtendimentoView'" Exception.

Expected behavior

A filter applyed in the attribute status

Actual behavior

I got Exception that there is not the status attribute, but the json prove that has the attribute:

[
 {
   "dataHoraAlteracao": "Mon, 31 Aug 2020 20:52:07 GMT",
   "status": "Em execução",
   "id": 548075,
   "area": "GETIN",
   "classificacao": "ATENDIMENTO WEB",
}
]

Steps to reproduce

Environment

Version: 1.5.0-Alpha5 JPA-Provider: Hibernate 3.2.1.ga DBMS: MSSQL Application Server: Java SE

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
beikovcommented, Sep 1, 2020

If you want to use final fields, you can use self-injection: https://persistence.blazebit.com/documentation/1.5/entity-view/manual/en_US/#using-attribute-getters-in-constructor

@EntityView(Atendimento.class)
public abstract class AtendimentoView implements BaseBlazeView {

	private String dataHoraAlteracao;
	private final String status;

	public AtendimentoView(@Mapping("dataAlteracao") Date dataHoraAlteracao, @Self AtendimentoView self) {
		....
		convertStatus(Optional.ofNullable(self.getStatus0()));
	}

	private void convertStatus(Optional<String> status) {
		....
	}

	@Mapping("status")
	@AttributeFilter(EqualFilter.class)
        abstract String getStatus0();

	public String getStatus() {
		return status;
	}
}
1reaction
beikovcommented, Sep 1, 2020

Hmm, I’m not sure I understand the problem. There are many ways how you can make this work. For example you could use the following:

@EntityView(Atendimento.class)
public abstract class AtendimentoView implements BaseBlazeView {

	private String dataHoraAlteracao;
	private String status;

	public AtendimentoView(@Mapping("dataAlteracao") Date dataHoraAlteracao) {
		....
        }

        @PostLoad
	void postLoad() {
		convertStatus(Optional.ofNullable(getStatus0()));
	}

	private void convertStatus(Optional<String> status) {
		....
	}

	@Mapping("status")
	@AttributeFilter(EqualFilter.class)
        abstract String getStatus0();

	public String getStatus() {
		return status;
	}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter condition using attributes defined in base class
I am using Hibernate 4.1 and had the same problem. This explains how to tell Hibernate which entity class your condition is actually...
Read more >
Class Abstraction - Manual
In an Abstract Class, you can define how some methods work, where as in an Object Interface you can not. An Object Interface...
Read more >
Abstract Classes in Python
An abstract method is a method that has a declaration but does not have an implementation. While we are designing large functional units...
Read more >
Effective Dart: Design
Dart is a “pure” object-oriented language in that all objects are instances of classes. But Dart does not require all code to be...
Read more >
ActionFilterAttribute Class (Microsoft.AspNetCore.Mvc.Filters)
An abstract filter that asynchronously surrounds execution of the action and the action result.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found