Hibernate - Dynamic Instantiation using factory

1

I know that using Hibernate Dynamic Instantiation I can instantiate an object according to a constructor.

The Problem: I need to optimize the system as much as I can, and I'm done creating 5+ constructors in the same class.

I want to know if it is possible to use the Factory standard together with Dynamic Instantiation.

Current HQL select new br.com.domain.dto.SolicitacaoDTO(s.id, s.beneficiario.nome, s.dataRegistro, s.statusSolicitacao) from Solicitacao s

If you could use the Factory default

select new br.com.factory.dto.SolicitacaoDTO.consulta(s.id, s.beneficiario.nome, s.dataRegistro, s.statusSolicitacao) from Solicitacao s 

If you have any suggestions on how to solve this problem otherwise, I'm open to suggestions or corrections.

    
asked by anonymous 28.03.2016 / 16:12

1 answer

1

If I have a good understanding of what you need, I can tell you that through the Hibernate documentation it does not offer the option to invoke a query resource when instantiating the object through Dynamic Instantiation.

It provides feature for use in a builder:

Example 11.27. Dynamic instantiation example - constructor(Doc do Hibernate)
select new Family( mother, mate, offspr )
   from DomesticCat as mother
   join mother.mate as mate
   left join mother.kittens as offspr

For use through the list:

Example 11.28. Dynamic instantiation example - list (Doc do Hibernate)
select new list(mother, offspr, mate.name)
  from DomesticCat as mother
  inner join mother.mate as mate
  left outer join mother.kittens as offspr

Or through maps:

Example 11.29. Dynamic instantiation example - map (Doc do Hibernate)
select new map( mother as mother, offspr as offspr, mate as mate )
   from DomesticCat as mother
   inner join mother.mate as mate
   left outer join mother.kittens as offspr
select new map( max(c.bodyWeight) as max, min(c.bodyWeight) as min, count(*) as n )from Cat c

Perhaps the optimization you want will be able to load the information you need for one of these formats.

    
28.03.2016 / 23:21