-
Notifications
You must be signed in to change notification settings - Fork 192
Breaking change from 4.2.7-SNAPSHOT
to 4.3.1
for repositories with abstract or interface entities
#1315
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
Comments
There was a change to create objects that match the return type instead of the entity type of the repository - to handle methods that use projections to create other types of objects. Looking... |
Hi - Can you provide an example of this? |
This is a nice improvement but it should not break current behavior in this major release branch. One solution could be to use the |
It's supposed to do that. That's the bug. In the change for matching the return type, projecting the _class (or typeKey) property was dropped. So it always fell back to the entity of the repository. The fix is simple. But obviously I need to add some test cases. As a hack, adding a _class property to the BaseManageableEntity class will result in the _class property of the document being projected, and the converter being able to figure out what to instantiate. protected String _class; |
Here is a close reproduction of my case : Entitiespublic abstract class AuditedEntity implements Serializable {
@Field("is_audited_entity")
protected boolean isAuditedEntity = true; // we use this as a class hierarchy root identifier.
@Id
@GeneratedValue(strategy = UNIQUE, delimiter = ID_DELIMITER)
protected String id;
@Version
@Field("revision")
protected Long revision;
@CreatedBy
@Field("created_by")
protected String createdById;
@CreatedDate
@Field("created_date")
protected Instant createdDate = Instant.now();
@LastModifiedBy
@Field("last_modified_by")
protected String lastModifiedById;
@LastModifiedDate
@Field("last_modified_date")
protected Instant lastModifiedDate = Instant.now();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreatedById() {
return createdById;
}
public void setCreatedBy(Customer customer) {
this.createdById = customer.getId();
}
public void setCreatedById(String createdBy) {
this.createdById = createdBy;
}
public Instant getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}
public String getLastModifiedById() {
return lastModifiedById;
}
public void setLastModifiedBy(Customer lastModifiedBy) {
this.lastModifiedById = lastModifiedBy.getId();
}
public void setLastModifiedById(String lastModifiedById) {
this.lastModifiedById = lastModifiedById;
}
public Instant getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Instant lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
public Long getRevision() {
return revision;
}
public void setRevision(long revision) {
this.revision = revision;
}
}
@Document
@Data
class EntityA extends AuditedEntity {
String specificPropOne;
}
@Document
@Data
class EntityB extends AuditedEntity {
String specificPropTwo;
} Repositoriespublic interface EntityARepository extends CouchbaseRepository<String, EntityA> {
}
public interface EntityBRepository extends CouchbaseRepository<String, EntityB> {
}
public interface AuditedEntityRepository extends Repository<String, AuditedEntity> {
@Query("SELECT * FROM #{#n1ql.bucket} WHERE is_audited_entity = true")
List<AuditedEntity> findAll();
} Then you should be able to retrieve all |
That's good. I actually was able to reproduce with the Foo/BaseManageableEntity from issue 1312. The fix is to change this is the addition of typeField on the entity projection in StringBasedN1qlQueryParser. As soon as I make some test cases I'll merge the fix to both main and 4.3.x
|
Restore projection of class in queries. This is necessary for abstract repositories. Closes #1315.
Restore projection of class in queries. This is necessary for abstract repositories. Closes #1315.
btw - derived queries (those without an @query definition) on a repository for an abstract entity class and the default type (i.e. no @typealias) will never select any rows that have been saved by that repository because the _class = predicate will use the abstract class name, while the documents will have been saved with their concrete class name. |
Restore projection of class in queries. This is necessary for abstract repositories. Closes #1315.
Is there an ETA for |
Restore projection of class in queries. This is necessary for abstract repositories. Closes #1315.
February 18. https://calendar.spring.io/ (2021.1.x -> 4.3.x) |
Restore projection of class in queries. This is necessary for abstract repositories. Closes #1315.
4.2.7-SNAPSHOT
to 4.3.1
4.2.7-SNAPSHOT
to 4.3.1
for repositories with abstract or interface entities
This repository method causes an issue with
4.3.1
but not with4.2.7-SNAPSHOT
:This method can return a variety of types of documents all extending the
BaseManageableEntity
abstract class.With
4.2.7-SNAPSHOT
the returned objects have the type of their inner class,A
orB
both extendingBaseManageableEntity
, the list carries the lower bound and is of typeList<BaseManageableEntity>
.With
4.3.1
the returned method tries to deserialize the documents as instances ofBaseManageableEntity
causing an error, sinceBaseManageableEntity
is an abstract class.The behavior of
4.2.7-SNAPSHOT
is the correct behavior imo, since it's easier and more natural to go in this direction than the other one.The text was updated successfully, but these errors were encountered: