Closes #1641
Related tickets #1386 #1343
I delete those code and execute sort 4 patterns.
if (associations.isLinkableAssociation(persistentProperty)) {
return Collections.emptyList();
}
Currently, it seems to support linkable associations.
Therefore, I have removed the check process for linkable associations.
Are there any other patterns that should be tested further?
Patterns result:
eager and exported
Path: /accounts_eager_and_exported?sort=accountType.typeName,desc
Query:
Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountEagerAndExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountEagerAndExported {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@RestResource(exported = true)
@JoinColumn(name = "account_type_id")
@ManyToOne(fetch = FetchType.EAGER)
private AccountType accountType;
}
Repository: AccountEagerAndExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountEagerAndExported;
@RepositoryRestResource(collectionResourceRel = "accounts_eager_and_exported", path = "accounts_eager_and_exported")
public interface AccountEagerAndExportedRepository extends JpaRepository<AccountEagerAndExported, Long> {
}
eager and no exported
Path: /accounts_eager_and_no_exported?sort=accountType.typeName,desc
Query:
Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountEagerAndNoExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountEagerAndNoExported {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@RestResource(exported = false)
@JoinColumn(name = "account_type_id")
@ManyToOne(fetch = FetchType.EAGER)
private AccountType accountType;
}
Repository: AccountEagerAndNoExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountEagerAndNoExported;
@RepositoryRestResource(collectionResourceRel = "accounts_eager_and_no_exported", path = "accounts_eager_and_no_exported")
public interface AccountEagerAndNoExportedRepository extends JpaRepository<AccountEagerAndNoExported, Long> {
}
lazy and exported
Path: accounts_lazy_and_exported?sort=accountType.typeName,desc
Query:
Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountLazyAndExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountLazyAndExported {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@RestResource(exported = true)
@JoinColumn(name = "account_type_id")
@ManyToOne(fetch = FetchType.LAZY)
private AccountType accountType;
}
Repository: AccountLazyAndExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountLazyAndExported;
@RepositoryRestResource(collectionResourceRel = "accounts_lazy_and_exported", path = "accounts_lazy_and_exported")
public interface AccountLazyAndExportedRepository extends JpaRepository<AccountLazyAndExported, Long> {
}
lazy and no exported
In the first place, it is not supported by Spring Data REST.
Example code repository: https://github.com/mikoto2000/spring-data-rest-example
Closes #1641
Related tickets #1386 #1343
I delete those code and execute sort 4 patterns.
spring-data-rest/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMappingAwareSortTranslator.java
Lines 195 to 197 in f0e86b9
Currently, it seems to support linkable associations.
Therefore, I have removed the check process for linkable associations.
Are there any other patterns that should be tested further?
Patterns result:
eager and exported
Path:
/accounts_eager_and_exported?sort=accountType.typeName,descQuery:
Entity: AccountEagerAndExported.java
Repository: AccountEagerAndExportedRepository.java
eager and no exported
Path:
/accounts_eager_and_no_exported?sort=accountType.typeName,descQuery:
Entity: AccountEagerAndNoExported.java
Repository: AccountEagerAndNoExportedRepository.java
lazy and exported
Path:
accounts_lazy_and_exported?sort=accountType.typeName,descQuery:
Entity: AccountLazyAndExported.java
Repository: AccountLazyAndExportedRepository.java
lazy and no exported
In the first place, it is not supported by Spring Data REST.
Example code repository: https://github.com/mikoto2000/spring-data-rest-example