{"id":213,"date":"2022-08-30T14:57:36","date_gmt":"2022-08-30T14:57:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/08\/23\/problem-about-criteria-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:57:36","modified_gmt":"2022-08-30T14:57:36","slug":"problem-about-criteria-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-criteria-record-and-share-programming-errors\/","title":{"rendered":"problem about criteria-Record and share programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aee3b44e5f0b4dfa0e2da672897b3751?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nj0k<br \/>\nmysql symfony1 criteria propel<br \/>\nI&#8217;m working on a symfony project and i need to query a many to many relationship, so i made this criteria based function to query the database:\/\/Create Criteria Object$c1 = new Criteria();\/\/Selecting the rows in the link table that m<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8f6337c8c7a1cf04dab80ae3a8c40150?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntirengarfio<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/89927e2f4bde24991649b353a37678b9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBalusC<br \/>\njava jpa criteria<br \/>\nI&#8217;m trying to do a search page that retrieves some data from my database using JPA 2.0 Criteria API. I&#8217;m getting the same exception error everytime I try to do the search.Here is my search method:public List search(SearchCommercialsDTO searchCommercialsDTO) {CriteriaBuilder builder = em.getCriteriaBuilder();CriteriaQuery criteria = builder.createQuery( Matches.class );Root matchesRoot = criteria.from( Matches.class );criteria.select( matchesRoot );List predicateList = new ArrayList();Predicate date, equipmentName, channelCode, advertiserName, agencyName, productName, duration;if(!ObjectUtil.isEmpty(searchCommercialsDTO.getEquipmentName())) {equipmentName = builder.like(matchesRoot.get(&#8220;ID_RECORDER_FILES.EQUIPMENT_NAME&#8221;).as(String.class), searchCommercialsDTO.getEquipmentName());predicateList.add(equipmentName);}if(!ObjectUtil.isEmpty(searchCommercialsDTO.getChannelCode())) {channelCode = builder.equal(matchesRoot.get(&#8220;ID_RECORDER_FILES.CHANNEL_CODE&#8221;), searchCommercialsDTO.getChannelCode());predicateList.add(channelCode);}if(!ObjectUtil.isEmpty(searchCommercialsDTO.getAdvertiserName())) {advertiserName = builder.equal(matchesRoot.get(&#8220;ID_SOURCE_MATERIAL.ADVERTISER_NAME&#8221;), searchCommercialsDTO.getAdvertiserName());predicat<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8f6337c8c7a1cf04dab80ae3a8c40150?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntirengarfio<br \/>\nsymfony1 criteria propel offset<br \/>\ni have this schema below, i have generated the classes using symfony and created a pair of objects using the form class generated.moto:marca: { type: varchar(255), required: true }matricula: { type: integer, required: true }Now i have this criteria:$c = new Criteria();$c-&gt;addSelectColumn(&#8216;MAX(&#8216;.MotoPeer::MATRICULA.&#8217;)&#8217;);$max_matricula = MotoPeer::doSelect($c);var_dump($max_matricula);return $max_matricula;When i call the criteria code It works ok, but these three notices below are showed.Any idea?sf 1.4\/propel 1.4( ! ) Notice: Undefined offset: 2 in\/opt\/lampp\/htdocs\/prueba\/lib\/model\/om\/BaseMotoPeer.php on line 379Call StackTime Memory Function Location 1 0.0008 328076{main}( ) ..\/frontend_dev.php:02 0.1974 4333236sfContext-&gt;dispatch( )..\/frontend_dev.php:13 3 0.1974 4333264sfFrontWebController-&gt;dispatch( )..\/ sfContext.class.php:170 40.1981 4350256 sfController-&gt;forward( ) ..\/sfFrontWebController.class.php:48 50.2134 4641000 sfFilterChain-&gt;execute( )..\/sfController.class.php: 238 60.2138 4641808 sfRenderingFilter-&gt;execute( )..\/ sfFilterChain.class.php:53 70.2138 4641808 sfFilterChain-&gt;execute( ) ..\/sfRenderingFilter.class.php:33 80.2143 4642588 sfExecutionFilter-&gt;execute( )..\/ sfFilterChain.class.php:53 90.2144 4643308 sfExecutionFilter-&gt;handleAction( )..\/ sfExecutionFilter.class.php:42 10 0.2144 4643308 sfExecutionFilter-&gt;executeAction( ) ..\/ sfExecutionFilter.class.php:78 11 0.2144 4643336 sfActions-&gt;execute( ) ..\/sfExecutionFil<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6bd72e91ca6e57e553998a9e5e1be593?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJonathan<br \/>\njava hibernate criteria<br \/>\nI need to convert the following HQL to CRITERIA:Query query = bd.getSession().createQuery(&#8220;from Booking as b &#8221; + &#8221; where &#8221; + &#8221; b.cadimp.cdCadimp = :cdCadimp AND &#8220;+ &#8221; b.dtEntrada &gt;= :dateParam AND &#8221; + &#8221; b.idCancelado &#8216;S&#8217; AND &#8221; + &#8221; b.cdNavio 141 AND &#8221; + &#8221; 0 = (select count(*) from Item i2 where &#8221; +&#8221; (&#8221; +&#8221; i2.pk.cdEmpresa = b.pedido.cdEmpresa &#8221; +&#8221; AND i2.pk.nrPedido = b.pedido.nrPedido &#8221; +&#8221; AND&#8221; +&#8221; (i2.cdTaxa &gt;= 101 &#8221; +&#8221; AND i2.cdTaxa &lt; 110) &#8221; +&#8221; AND i2.flag = &#8216;R'&#8221; +&#8221; AND i2.dtPagto &#8216;0001-01-01&#8242;&#8221; +&#8221; )&#8221; +&#8221; )&#8221;+ &#8221; ORDER BY b.dtInformacao asc&#8221;);My criteria:Criteria c = getSession().createCriteria(Booking.class, &#8220;b&#8221;).add(Restrictions.eq(&#8220;cadimp.cdCadimp&#8221;,(Integer) restrictionsValues[0])).add(Restrictions.gt(&#8220;dtEntrada&#8221;, calendar.getTime())).add(Restrictions.ne(&#8220;idCancelado&#8221;, &#8220;S&#8221;)).add(Restrictions.ne(&#8220;cdNavio&#8221;, (short) 141)).add(Subqueries.eq(0,DetachedCriteria.forClass(Item.class, &#8220;i&#8221;).add(Restrictions.eqProperty(&#8220;cdEmpresa&#8221;, &#8220;b.pedido.cdEmpresa&#8221;)).add(Restrictio<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/157611e1920cebabac9c1502efcc28ab?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFinalArt2005<br \/>\njava hibernate postgresql group-by criteria<br \/>\nI&#8217;m having some trouble with an sql query. I&#8217;m using Hibernate Criteria to build the query. I create some bins from a database by rounding the values with certain intervals (the binSize) and then grouping them. This works great when I try it directly in SQL with the query:SELECT floor(phiTorsionAngle \/ 2) * 2 as phiTorsionAngleBin, floor(psiTorsionAngle \/ 2) * 2 as psiTorsionAngleBin, floor(phiTorsionAngle \/ 2) + 180 as phiTorsionAngleBinIndex, floor(psiTorsionAngle \/ 2) + 180 as psiTorsionAngleBinIndex, count(*) as numberOfResidues FROM residueWHERE phitorsionangle IS NOT NULLAND psitorsionangle IS NOT NULLGROUP BY phiTorsionAngleBin, psiTorsionAngleBinBut when I try it with Hibernate Criteria it fails. This is the code to build the query:ScrollableResults phiPsiBins = createCriteria() .setProjection(Projections.projectionList().add(Projections.sqlGroupProjection(&#8220;floor(phiTorsionAngle \/ &#8221; + binSize + &#8220;) * &#8221; + binSize + &#8221; as phiTorsionAngleBin, &#8221; +&#8221;floor(psiTorsionAngle \/ &#8221; + binSize + &#8220;) * &#8221; + binSize + &#8221; as psiTorsionAngleBin, &#8221; + &#8220;floor(phiTorsionAngle \/ &#8221; + binSize + &#8220;) + 180 as phiTorsionAngleBinIndex, &#8221; +&#8221;floor(psiTorsionAngle \/ &#8221; + binSize + &#8220;) + 180 as psiTorsionAngleBinIndex, &#8221; + &#8220;count(*) as numberOfResidues&#8221;,&#8221;phiTorsionAngleBin, psiTorsionAngleBin&#8221;,new String[] {&#8220;phiTorsionAngleBin&#8221;, &#8220;psiTorsionAngleBin&#8221;, &#8220;phiTorsionAngleBinIndex&#8221;, &#8220;psiTorsionAngleBinIndex&#8221;, &#8220;n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/feaeea6d2939022c49dc8b3a0510df43?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nEduardo Born<br \/>\njava hibernate query syntax criteria<br \/>\nI&#8217;m having a hard time constructing a criteria query to get the &#8220;permissions&#8221; attribute from the Role entity with id = 2. The permission attribute is of Set type, so I&#8217;m creating a join and selecting from it, but the query fails with invalid grammar exception reporting &#8220;Unknown column &#8216;2L&#8217; in &#8216;where clause'&#8221;The criteria query that generates the error was built this way:EntityManager entityManager = getEntityManager(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();Class queryScopeClass = temp.pack.commons.user.Role.class;Root from = criteriaQuery.from(queryScopeClass);Path idAttrPath = from.get(&#8220;id&#8221;); \/\/ also tried criteriaBuilder.equal(attributePath, new Long(2)) Predicate predicate = criteriaBuilder.equal(attributePath, criteriaBuilder.literal(new Long(2))) criteriaQuery.where(predicate);Path attributePath = from.get(&#8220;permissions&#8221;); PluralAttributePath pluralAttrPath = (PluralAttributePath)attributePath; PluralAttribute pluralAttr = pluralAttrPath.getAttribute();Join join = from.join((SetAttribute)pluralAttr);TypedQuery typedQuery = entityManager.createQuery(criteriaQuery.select(join)); return (List<\/p>\n<p>)typedQuery.getResultList();When I execute the line to actually return the results, the following exception is thrown:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute queryat org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:250)at o<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/19a55621e2d2441600c26df6d5a2d49c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nb_gunay<br \/>\njava hibernate query criteria jpa-2.0<br \/>\nI&#8217;ve a war application using hibernate-jpa 2.0, SiteListig is my entity, I want to make a criteria query, my code looks like:class Listing{ private Predicate criteria; @PersistenceContext private EntityManager em; private Root criteriaRoot; @Pattern(regexp=&#8221;([a-zA-Z0-9_\\\\s]+?|^$)&#8221;, message=&#8221;invalid filter&#8221;) private String addressFilter;public void setAddressFilter(String addressFilter) { this.addressFilter = addressFilter; \/\/ apply this as a filter CriteriaBuilder cb = getCriteriaBuilder(); Root root = getCriteriaRoot(); setCriteria(cb.like(root.get(&#8220;siteAddress&#8221;), &#8220;%&#8221;+addressFilter.trim() + &#8220;%&#8221;)); }protected CriteriaQuery getCriteriaQuery(){this.criteriaQuery =getCriteriaBuilder().createQuery(getClassType());return this.criteriaQuery; }protected CriteriaBuilder getCriteriaBuilder(){this.criteriaBuilder = Objects.firstNonNull(this.criteriaBuilder, em.getCriteriaBuilder());return this.criteriaBuilder; }public void anotherMethod(){ Query q = em.createQuery(getCriteriaQuery()); } }This line: Query q = em.createQuery(getCriteriaQuery()); gives this error: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Duplicate definition of alias &#8216;generatedAlias0&#8217; [select generatedAlias0 from com.sample.package.bean.Website as generatedAlias0, com.sample.package.bean.Website as generatedAlias0, com.sample.package.bean.Website as generatedAlias1 where generatedAlias0.url like :param0] Stack Trace:avax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Duplicate definition of alias &#8216;generatedAlias0&#8217; [select generatedAlias0 from com.sample.package.bean.Website as generatedAlias0, com.sample.package.bean.Website as generatedAlias0, com.sample.package.bean.Website as generatedAlias1 where generatedAlias0.url like :param0]at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:183)at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:251)at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.required(CMTTxInterceptor.java:349)at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invoke(CMTTxInterceptor.java:209)at org.jboss.ejb3.tx2.aop.CMTTxInterceptorWrapper.invoke(CMTTxInterceptorWrapper.java:52)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86)at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:323)at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:156)at org.jboss.ejb3.nointerface.impl.invocationhandler.NoInterfaceViewInvocationHandler.invokeEndpoint(NoInterfaceViewInvocationHandler.java:143)at org.jboss.ejb3.nointerface.impl.invocationhandler.NoInterfaceViewInvocationHandler.access$000(NoInterfaceViewInvocationHandler.java:54)at org.jboss.ejb3.nointerface.impl.invocationhandler.NoInterfaceViewInvocationHandler$1.invoke(NoInterfaceViewInvocationHandler.java:103)at org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler$1.proceed(InterceptorInvocationHandler.java:84)at org.jboss.ejb3.sis.InterceptorAssembly$1.proceed(InterceptorAssembly.java:82)at org.jboss.ejb3.nointerface.impl.async.AsyncClientInterceptor.invoke(AsyncClientInterceptor.java:119)at org.jboss.ejb3.sis.InterceptorAssembly$1.proceed(InterceptorAssembly.java:74)at org.jboss.ejb3.nointerface.imp<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8f6337c8c7a1cf04dab80ae3a8c40150?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntirengarfio<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-08-23 18:04:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>j0k mysql symfony1 criteria propel I&#8217;m working on a symfony project and i need to query a many to many relationship, so i made this criteria based function to query the database:\/\/Create Criteria Object$c1 = new Criteria();\/\/Selecting the rows in the link table that m tirengarfio BalusC java jpa criteria I&#8217;m trying to do a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}