For some reason JmixDataRepository fails to find a single entity in the database, despite that I checked they do exist.
The code for the repository:
public interface TournamentRepository extends JmixDataRepository<Tournament_, Long> {
Optional<Tournament_> findBySlug(String slug);
}
Tournament_ entity:
@JmixEntity
@Table(name = "TOURNAMENT_", indexes = {
@Index(name = "IDX_TOURNAMENT__AUTHOR", columnList = "AUTHOR_ID"),
@Index(name = "IDX_TOURNAMENT__SCORING_METHOD", columnList = "SCORING_METHOD_ID"),
@Index(name = "IDX_TOURNAMENT_SCORINGTEMPLATE", columnList = "SCORING_TEMPLATE_ID"),
@Index(name = "IDX_TOURNAMENT__ON_ROOM", columnList = "ROOM_ID", unique = true)
})
@Entity
public class Tournament_ {
@Column(name = "ID", nullable = false)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "IS_FINISHED", nullable = false)
@NotNull
private Boolean isFinished = false;
}
The service calls repository here:
public Page<Tournament_> getPage(Integer page, Integer size) {
System.out.println("Entities found: " + tournamentRepository.count());
return tournamentRepository.findAll(PageRequest.of(page, size));
}
I added a print statement to do some debugging.
// Entities found: 0
But there is a record in the database.
At this position, I am stuck and have no idea of the direction to look for the answer. I googled the question but it seems nobody had this problem.
Maybe you need to check if the user has permission to read the entity
Tournament_.There is an annotation
@ApplyConstraints, which determines whether to useDataManagerorUnconstrainedDataManagerin repositories. The default value is true(use DataManager), and it's applied on interfaceJmixDataRepository. That means, if your user has no permission to read corresponding entity, the count result should be 0.@ApplyConstraintscan be applied on both Repository interface or method.BTW, you can use https://forum.jmix.io to ask Jmix questions and the dev team is really helping there.