Hibernate - Dynamic Instantiation using Factory

Asked

Viewed 69 times

1

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

The Problem: I need to optimize the system as much as possible, and with that ended up creating 5+ builders in the same class.

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

HQL Atual 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 standard

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 am open to suggestions or corrections.

1 answer

1


If I could understand well what you need, I can say that through the Hibernate documentation it does not offer the option to call a query resource when instantiating the object through Dynamic Instantiation.

It enables feature for use in a constructor:

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 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

Maybe the optimization you want is to be able to upload the information you need to one of these formats.

  • That way you posted what I’m doing today. However the way I want (delegate to a Factory or Builder) to do is not possible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.