我使用EntityGraph创建我的实体:
@Entity(name = "protocolo")
@TypeDefs({@TypeDef(name = "JsonObjetoProtocoloUserType", typeClass = JsonObjetoProtocoloUserType.class),
@TypeDef(name = "JsonServicoCalculadoUserType", typeClass = JsonServicoCalculadoUserType.class)})
@SuppressWarnings("serial")
@NamedEntityGraphs({
@NamedEntityGraph( name = "Protocolo.grid", attributeNodes = {
@NamedAttributeNode(value = "tipo"),
@NamedAttributeNode(value = "natureza"),
@NamedAttributeNode(value = "cliente"),
@NamedAttributeNode(value = "subNatureza"),
@NamedAttributeNode(value = "statusProtocolo", subgraph = "FetchManagers.Subgraph.Status")
},
subgraphs = {
@NamedSubgraph(name = "FetchManagers.Subgraph.Status", type = StatusProtocolo.class, attributeNodes = {@NamedAttributeNode(value = "status")}),
@NamedSubgraph(name = "FetchManagers.Subgraph.Status", type = StatusProtocolo.class, attributeNodes = {@NamedAttributeNode(value = "usuario")})
}),
@NamedEntityGraph( name = "Protocolo.tudo", attributeNodes = {
@NamedAttributeNode(value = "tipo"),
@NamedAttributeNode(value = "natureza"),
@NamedAttributeNode(value = "cartorioParceiro"),
@NamedAttributeNode(value = "formaEntrega"),
@NamedAttributeNode(value = "partesProtocolo"),
@NamedAttributeNode(value = "intimacaosProtocolo"),
@NamedAttributeNode(value = "checklist"),
@NamedAttributeNode(value = "objetos"),
@NamedAttributeNode(value = "cliente"),
@NamedAttributeNode(value = "subNatureza"),
@NamedAttributeNode(value = "statusProtocolo", subgraph = "FetchManagers.Subgraph.Status")
},
subgraphs = {
@NamedSubgraph(name = "FetchManagers.Subgraph.Status", type = StatusProtocolo.class, attributeNodes = {@NamedAttributeNode(value = "status")}),
@NamedSubgraph(name = "FetchManagers.Subgraph.Status", type = StatusProtocolo.class, attributeNodes = {@NamedAttributeNode(value = "usuario")})
})
})
public class Protocolo extends AbstractEntity{
protected static Logger logger= LoggerFactory.getLogger(Protocolo.class);
Long numero;
@Column(name = "tipo_protocolo_id")
@Convert(converter = TipoProtocoloConverter.class)
@NotNull
private TipoProtocolo tipo;
@OneToOne
@NotNull
private Natureza natureza;
@OneToOne
private CartorioParceiro cartorioParceiro;
@OneToOne
private SubNatureza subNatureza;
@OneToOne(fetch = FetchType.LAZY)
@NotNull
private FormaEntrega formaEntrega;
@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name="protocolo_id")
@JsonIgnore
Set<ParteProtocolo> partesProtocolo;
@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name="protocolo_id")
@NotNull
private Set<StatusProtocolo> statusProtocolo;
@JsonIgnore
@Type(type = "JsonServicoCalculadoUserType")
List<ServicoCalculado> servicos;
@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name="protocolo_id")
@JsonIgnore
Set<IntimacaoProtocolo> intimacaosProtocolo;
private Integer vias = 0;
@Column
@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "BRL")})
@JsonIgnore
private Money valor;
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate data_doc;
@NotEmpty
private String parte;
@NotEmpty
@CpfCnpj
private String parteDocumento;
@Column(name = "data_protocolo")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dataProtocolo = LocalDateTime.now();
@Column(name = "dt_protocolo_informado_portal")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dataProtocoloInformadoPortal;
@Column(name = "dt_registro_informado_portal")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dataRegistroInformadoPortal;
@Column(name = "dt_certidao_informado_portal")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dataCertidaoInformadoPortal;
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate data_prevista;
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate data_vencimento;
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime data_entrega;
@Column(name = "pasta_pj")
private String pastaPJ;
private String responsavel;
@NotEmpty
private String apresentante;
private String apresentante_rg;
private String telefone;
@Email
private String email;
@Column(length=10485760)
private String observacoes;
@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name="protocolo_id")
@JsonIgnore
private Set<ChecklistProtocolo> checklist;
@Type(type = "JsonObjetoProtocoloUserType")
@JsonIgnore
private List<ObjetoProtocoloVO> objetos;
@Column( name = "registro_referencia")
private String registroReferencia;
@Column( name = "numero_registro_referencia")
private Long numeroRegistroReferencia;
@Column( name = "numero_registro")
private String numeroRegistro;
@Column( name = "observacao_registro", length=10485760)
private String observacaoRegistro;
@Column( name = "situacao_atual_registro",length=10485760)
private String situacaoAtualRegistro;
@Column(name = "dt_registro")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dtRegistro;
@Column(name = "dt_devolvido")
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDateTime dtDevolvido;
@Column Long nrExameCalculoReferencia;
@Column(length=10485760, name = "texto_carimbo")
@JsonIgnore
private String textoCarimbo;
@Column(length=10485760, name = "texto_certidao")
@JsonIgnore
private String textoCertidao;
@JsonIgnore
@OneToOne
private Cliente cliente;
@Column(name = "ic_guarda_conservacao")
private Boolean icGuardaConservacao = false;
@Column(name = "ic_possui_sigilo_legal")
private Boolean icPossuiSigiloLegal = false;
@Column(name = "pedido_id")
private Long pedido;
...
}
但是现在我需要对结果进行分页,当我在使用一个@EntityGraph的存储库中运行方法时,分页不起作用(我记录了休眠sql,当我删除@EntityGraph时,限制和偏移量显示在日志中,如果我将@EntityGraph放入限制和偏移量,则不会出现)
这是我运行sql的代码:
不工作
@Override
@EntityGraph(value = "Protocolo.grid", type = EntityGraph.EntityGraphType.FETCH)
Page<Protocolo> findAll( Pageable pageable);
工作
@Override
Page<Protocolo> findAll( Pageable pageable);