Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seems you have 3 different forms of entity. E.g. for the "procedure" "FinDetachement":</p> <ul> <li>TypeDocFinDetachement</li> <li>DocFinDetachement</li> <li>FinDetachement</li> </ul> <p>It's not clear why you need the 3 (obviously, reduce the number if you can). Anyway, assuming you do need all 3...</p> <ol> <li><p>Introduce a common <em>abstract</em> ancestor classes for each of "type document" and "document" and "procedure" and use @Inheritance (see <a href="http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch05.html#d5e3306" rel="nofollow">Hibernate Docs</a>):</p> <pre><code>@Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) // Other strategies would also work public abstract class TypeDocument { // put common document fields &amp; methods here - // if you can work out what they are (they do exist - even if minor!) @Id Integer id; String step; // etc } @Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) // Other strategies would also work public abstract class Document { // put common document fields &amp; methods here - // if you can work out what they are (they do exist - even if minor!) } @Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) // Other strategies would also work public abstract class Procedure { // put common document fields &amp; methods here - // if you can work out what they are (they do exist - even if minor!) } </code></pre></li> <li><p>Extend these for your actual entities:</p> <pre><code>@Entity public class TypeDocFinDetachement extends TypeDocument { // put specific fields &amp; methods here } @Entity public class DocFinDetachement extends Document { // put specific fields &amp; methods here } @Entity public class FinDetachement extends Procedure { // put specific fields &amp; methods here } </code></pre></li> <li><p>Introduce a common generic DAO for JPA logic</p> <pre><code>public abstract class ProcedureDAO&lt;T extends TypeDocument, D extends Document, P extends Procedure&gt; { public P findById(Integer id) { // put "procedure" query logic here } public void execProcedure(Class typeDocumentClass, String typeDocName, Class docClass, String docName, String step, String procedureId) { //******************list des document liés à l'étape Session se = HibernateSessionFactory.getSession(); Criteria cr = se.createCriteria(typeDocumentClass); cr.add(Restrictions.eq("step",step)); List&lt;T&gt; list = cr.list(); Iterator&lt;T&gt; iterator = list.iterator(); //------------------------ procédure fin détachement en question P procedure =null; if(sid != "") { Integer id = Integer.parseInt(procedureId); procedure = findById(id); } //*************list des document déjà scannées // Session sess = HibernateSessionFactory.getSession(); Criteria criteria = sess.createCriteria(docClass); //criteria.add(Restrictions.eq(docName,doc)); criteria.createAlias(typeDocName, "t"); criteria.add(Restrictions.eq("t.step",step)); List&lt;D&gt; listdoc = criteria.list(); Iterator&lt;D&gt; it = listdoc.iterator(); // etc } } </code></pre></li> <li><p>If possible, put all JPA logic into the ancestor DAO and instantiate it and call it "inline". E.g.:</p> <pre><code>public class SomeOtherClass { public void someMethod() { ProcedureDAO&lt;TypeDocFinDetachement, DocFinDetachement, FinDetachement&gt; finDetachementDAO = new ProcedureDAO(); finDetachementDAO.execProcedure(TypeDocFinDetachement.class, "typeDocFinDetachement", DocumentFinDetachement.class, "finDetachement", "someStage"); } } </code></pre></li> <li><p>If 4 is not possible, create extension DAOs (but only if absolutely necessary, because logic must change significantly):</p> <pre><code>public class FinDetachementDAO extends ProcedureDAO&lt;TypeDocFinDetachement, DocFinDetachement, FinDetachement&gt; { // extend/override JPA logic here } public class SomeOtherClass { public void someMethod() { FinDetachementDAO finDetachementDAO = new FinDetachementDAO(); finDetachementDAO.execProcedure(TypeDocFinDetachement.class, "typeDocFinDetachement", DocumentFinDetachement.class, "finDetachement", "someStage"); } } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload