SEAM ENTITYQUERY - 限制seam-gem示例的问题

时间:2009-10-09 16:12:27

标签: java seam ejbql

我的项目最初是由seam-gen生成的,动作“List”bean没有像我预期的那样工作。限制数组具有表中的所有属性,并且表现得好像所有参数都是必需的。参见List Bellow:

package br.com.autenticis.comvenif_red_web.session;

import br.com.autenticis.comvenif_red_web.entity.*;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import java.util.Arrays;

@Name("t233Ev01List")
public class T233Ev01List extends EntityQuery<T233Ev01> {

 private static final String EJBQL = "select t233Ev01 from T233Ev01 t233Ev01";

 private static final String[] RESTRICTIONS = {
   //"lower(t233Ev01.placaUnica) like lower(concat(#{t233Ev01List.t233Ev01.placaUnica},'%'))",}; 
   "lower(t233Ev01.placaUnica) like lower(concat(#{t233Ev01List.t233Ev01.placaUnica},'%'))",
   "lower(t233Ev01.renavam) like lower(concat(#{t233Ev01List.t233Ev01.renavam},'%'))",
   "lower(t233Ev01.numIdentProprietario) like lower(concat(#{t233Ev01List.t233Ev01.numIdentProprietario},'%'))",
   "lower(t233Ev01.nomeProprietario) like lower(concat(#{t233Ev01List.t233Ev01.nomeProprietario},'%'))",
   "lower(t233Ev01.anoFabricacao) like lower(concat(#{t233Ev01List.t233Ev01.anoFabricacao},'%'))",
   "lower(t233Ev01.anoModelo) like lower(concat(#{t233Ev01List.t233Ev01.anoModelo},'%'))",
   "lower(t233Ev01.ufByUfEmissao) like lower(concat(#{t233Ev01List.t233Ev01.ufByUfEmissao},'%'))",
   "lower(t233Ev01.numeroCrv) like lower(concat(#{t233Ev01List.t233Ev01.numeroCrv},'%'))",
   "lower(t233Ev01.dataEmissao) like lower(concat(#{t233Ev01List.t233Ev01.dataEmissao},'%'))",
   "lower(t233Ev01.numeroVia) like lower(concat(#{t233Ev01List.t233Ev01.numeroVia},'%'))",
   "lower(t233Ev01.codigoSegurancaCrv) like lower(concat(#{t233Ev01List.t233Ev01.codigoSegurancaCrv},'%'))",
   "lower(t233Ev01.tipoDocCartorio) like lower(concat(#{t233Ev01List.t233Ev01.tipoDocCartorio},'%'))",
   "lower(t233Ev01.numIdentCartorio) like lower(concat(#{t233Ev01List.t233Ev01.numIdentCartorio},'%'))",
   "lower(t233Ev01.numIdentCv) like lower(concat(#{t233Ev01List.t233Ev01.numIdentCv},'%'))",};

 private T233Ev01 t233Ev01;

 public T233Ev01List() {
  t233Ev01 = new T233Ev01();
  t233Ev01.setId(new T233Ev01Id());
  setEjbql(EJBQL);

  setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
  setMaxResults(25);
 }

 public T233Ev01 getT233Ev01() {
  return t233Ev01;
 }
}

当我只是填写表格中的“Placa Unica”字段时,会生成一个包含所有字段的SQL,如下所示:

SELECT *
  FROM (SELECT t233ev01x0_.idtransacao AS idtransa1_26_,
               t233ev01x0_.dia_juliano AS dia2_26_,
               t233ev01x0_.uf_imovel_comprador AS uf38_26_,
               t233ev01x0_.uf_imovel_cartorio AS uf37_26_,
               t233ev01x0_.uf_emissao AS uf36_26_,
               t233ev01x0_.placa_unica AS placa3_26_,
               t233ev01x0_.renavam AS renavam26_,
               t233ev01x0_.num_ident_proprietario AS num5_26_,
               t233ev01x0_.nome_proprietario AS nome6_26_,
               t233ev01x0_.ano_fabricacao AS ano7_26_,
               t233ev01x0_.ano_modelo AS ano8_26_,
               t233ev01x0_.numero_crv AS numero9_26_,
               t233ev01x0_.data_emissao AS data10_26_,
               t233ev01x0_.numero_via AS numero11_26_,
               t233ev01x0_.codigo_seguranca_crv AS codigo12_26_,
               t233ev01x0_.tipo_doc_comprador AS tipo13_26_,
               t233ev01x0_.num_ident_comprador AS num14_26_,
               t233ev01x0_.nome_comprador AS nome15_26_,
               t233ev01x0_.nome_logradouro_comprador AS nome16_26_,
               t233ev01x0_.numero_imovel_comprador AS numero17_26_,
               t233ev01x0_.complemento_imovel_comprador AS complem18_26_,
               t233ev01x0_.bairro_imovel_comprador AS bairro19_26_,
               t233ev01x0_.cod_municipio_imovel_comprador AS cod20_26_,
               t233ev01x0_.cep_imovel_comprador AS cep21_26_,
               t233ev01x0_.cod_municipio_local_venda AS cod22_26_,
               t233ev01x0_.data_venda AS data23_26_,
               t233ev01x0_.tipo_doc_cartorio AS tipo24_26_,
               t233ev01x0_.num_ident_cartorio AS num25_26_,
               t233ev01x0_.nome_cartorio AS nome26_26_,
               t233ev01x0_.nome_logradouro_cartorio AS nome27_26_,
               t233ev01x0_.numero_imovel_cartorio AS numero28_26_,
               t233ev01x0_.complemento_imovel_cartorio AS complem29_26_,
               t233ev01x0_.bairro_imovel_cartorio AS bairro30_26_,
               t233ev01x0_.cod_municipio_imovel_cartorio AS cod31_26_,
               t233ev01x0_.cep_imovel_cartorio AS cep32_26_,
               t233ev01x0_.ddd_tel_cartorio AS ddd33_26_,
               t233ev01x0_.num_tel_cartorio AS num34_26_,
               t233ev01x0_.num_ident_cv AS num35_26_
          FROM autenticis_comvenif.t233_ev01 t233ev01x0_
         WHERE (LOWER (t233ev01x0_.renavam) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.ano_fabricacao) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.ano_modelo) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.numero_crv) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.data_emissao) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.numero_via) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.tipo_doc_cartorio) LIKE LOWER (? || '%'))
           AND (LOWER (t233ev01x0_.num_ident_cv) LIKE LOWER (? || '%')))
 WHERE ROWNUM <= ?

我不想放入查询,未填充的字段(null)。我没有找到任何关于“动态限制”的例子,你用EntityQuery

做另一种方法

1 个答案:

答案 0 :(得分:0)

Cateno,这看起来很像我发生的事情。在我的例子中,有问题的实体是一个视图,而不是一个表,因此seam / hibernate找不到要用作其Id的主键字段。

对于此视图,seam generate-entities创建了2个实体,一个仅包含一个id,另一个包含某种具有所有其他字段的子实体。我真的不明白它做了什么或为什么。相应的EntityList我看起来很可疑,就像你在这里发布的那样。

我解决这个问题的方法是在seam-gen.reveng.xml文件中明确定义此实体的主要子项。该文件位于resources文件夹中。这里的示例是我的reveng.xml文件中的条目:

<table name="office_view">
    <primary-key>
        <key-column name='office_id' />
    </primary-key>
</table>

如果这是您的问题,请在此处明确定义主键可能会对您有所帮助。

april26