在Criteria hibernate String中获取特定值

Get a specific value in Criteria hibernate String

我需要提取标准字符串的一些值。 概念是获取真正的SQL句和他的参数(无log)

目前,我用它来获取 Select:

CriteriaImpl c = (CriteriaImpl) criteria;
       SessionImpl s = (SessionImpl)c.getSession();
       SessionFactoryImplementor factory = s.getFactory();
       CriteriaQueryTranslator translator=new CriteriaQueryTranslator(factory,c,c.getEntityOrClassName(),CriteriaQueryTranslator.ROOT_SQL_ALIAS);
       String[] implementors = factory.getImplementors( c.getEntityOrClassName() );

       CriteriaJoinWalker walker = new CriteriaJoinWalker((OuterJoinLoadable)factory.getEntityPersister(implementors[0]), 
                               translator,
                               factory, 
                               c, 
                               c.getEntityOrClassName(), 
                               s.getLoadQueryInfluencers());


       String sql=walker.getSQLString();

结果:

select this_.ID_ELEMENTO as ID1_72_32_, this_2_.ACTIVO as[....]where this_2_.FECHA_BAJA is null and this_2_.ID_TIPO_ELEMENTO=? and this_2_.ACTIVO=? order by this_.ID_ELEMENTO asc

最接近获取参数的东西:

CriteriaQueryTranslator subCriteria= new CriteriaQueryTranslator(factory, c, c.getEntityOrClassName(), CriteriaQueryTranslator.ROOT_SQL_ALIAS);


       String root =subCriteria.getRootCriteria().toString();

结果:

CriteriaImpl(com.itym.pojo.elementos.antenas.AntenaAnalogicaPojo:elemento[Subcriteria(tipoElemento:tipoElemento)][fechaBaja is null, tipoElemento=ANTENA, activo=true])

我需要 "TipoElemento" 和 "activo" 值来替换第一个字符串。

我尝试了正则表达式,但没有离开我。

如果有人知道如何,或者其他方法得到真正的select,将不胜感激!

我认为这就是您想要的,如果不是,请纠正我: 这两个值都可以用这个正则表达式

/tipoElemento=([A-Za-z]*).*activo=([A-Za-z]*)/