vendredi 29 juillet 2016

Nested if's and cases in hibernate

First of all I am totally new to Hibernate. I managed to write following query:

"select new ShallowPayment(" +
                    "p.id, " +
                    "l2.id, " +
                    "l1.id, " +
                    "l0.id, " +
                    "p.repository.code, " +
                    "l0.workflow.config.code, " +
                    "p.errorReasonCode," +
                    "p.errorReasonDescription," +
                    "p.lastUpdateTimestamp%s) " +
                    "from com.trax.payment.hibernate.Payment p " +
                    "join p.repository as repo " +
                    "join p.envelope as l2 " +
                    "join l2.parentEnvelope as l1 " +
                    "join l1.parentEnvelope as l0 " +
                    "where p.datamart = :%s and p.workflow.routing.sourceFormat.code in (:%s) and " +
                    "(repo.code in (:%s) or l0.repository.code in (:%s)) " +
                    "order by p.creationDate desc, p.id desc"; 

I want to make a a select statement, where I have 4 objects, where I choose 1 ID from to insert:

  • p
  • l2
  • l1
  • l0

I want to make a value insert that when

p.workflow.routing.internalClassificationType.id > 1 I choose, the id of p, otherwise I go to:

l2.workflow.routing.internalClassificationType.id > 1

In that case, I choose l2, otherwise I go to l1, like

l1.workflow.routing.internalClassificationType.id > 1

And if even l2 isn't bigger than 1, I take the l0.workflow.routing.internalClassificationType.id

But how can I implement these statements in an IF/ELSE or Case in Hibernate?

Aucun commentaire:

Enregistrer un commentaire