problem about criteria-Record and share programming errors
j0k
mysql symfony1 criteria propel
I’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’m trying to do a search page that retrieves some data from my database using JPA 2.0 Criteria API. I’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(“ID_RECORDER_FILES.EQUIPMENT_NAME”).as(String.class), searchCommercialsDTO.getEquipmentName());predicateList.add(equipmentName);}if(!ObjectUtil.isEmpty(searchCommercialsDTO.getChannelCode())) {channelCode = builder.equal(matchesRoot.get(“ID_RECORDER_FILES.CHANNEL_CODE”), searchCommercialsDTO.getChannelCode());predicateList.add(channelCode);}if(!ObjectUtil.isEmpty(searchCommercialsDTO.getAdvertiserName())) {advertiserName = builder.equal(matchesRoot.get(“ID_SOURCE_MATERIAL.ADVERTISER_NAME”), searchCommercialsDTO.getAdvertiserName());predicat
tirengarfio
symfony1 criteria propel offset
i 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->addSelectColumn(‘MAX(‘.MotoPeer::MATRICULA.’)’);$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->dispatch( )../frontend_dev.php:13 3 0.1974 4333264sfFrontWebController->dispatch( )../ sfContext.class.php:170 40.1981 4350256 sfController->forward( ) ../sfFrontWebController.class.php:48 50.2134 4641000 sfFilterChain->execute( )../sfController.class.php: 238 60.2138 4641808 sfRenderingFilter->execute( )../ sfFilterChain.class.php:53 70.2138 4641808 sfFilterChain->execute( ) ../sfRenderingFilter.class.php:33 80.2143 4642588 sfExecutionFilter->execute( )../ sfFilterChain.class.php:53 90.2144 4643308 sfExecutionFilter->handleAction( )../ sfExecutionFilter.class.php:42 10 0.2144 4643308 sfExecutionFilter->executeAction( ) ../ sfExecutionFilter.class.php:78 11 0.2144 4643336 sfActions->execute( ) ../sfExecutionFil
Jonathan
java hibernate criteria
I need to convert the following HQL to CRITERIA:Query query = bd.getSession().createQuery(“from Booking as b ” + ” where ” + ” b.cadimp.cdCadimp = :cdCadimp AND “+ ” b.dtEntrada >= :dateParam AND ” + ” b.idCancelado ‘S’ AND ” + ” b.cdNavio 141 AND ” + ” 0 = (select count(*) from Item i2 where ” +” (” +” i2.pk.cdEmpresa = b.pedido.cdEmpresa ” +” AND i2.pk.nrPedido = b.pedido.nrPedido ” +” AND” +” (i2.cdTaxa >= 101 ” +” AND i2.cdTaxa < 110) ” +” AND i2.flag = ‘R'” +” AND i2.dtPagto ‘0001-01-01′” +” )” +” )”+ ” ORDER BY b.dtInformacao asc”);My criteria:Criteria c = getSession().createCriteria(Booking.class, “b”).add(Restrictions.eq(“cadimp.cdCadimp”,(Integer) restrictionsValues[0])).add(Restrictions.gt(“dtEntrada”, calendar.getTime())).add(Restrictions.ne(“idCancelado”, “S”)).add(Restrictions.ne(“cdNavio”, (short) 141)).add(Subqueries.eq(0,DetachedCriteria.forClass(Item.class, “i”).add(Restrictions.eqProperty(“cdEmpresa”, “b.pedido.cdEmpresa”)).add(Restrictio
FinalArt2005
java hibernate postgresql group-by criteria
I’m having some trouble with an sql query. I’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(“floor(phiTorsionAngle / ” + binSize + “) * ” + binSize + ” as phiTorsionAngleBin, ” +”floor(psiTorsionAngle / ” + binSize + “) * ” + binSize + ” as psiTorsionAngleBin, ” + “floor(phiTorsionAngle / ” + binSize + “) + 180 as phiTorsionAngleBinIndex, ” +”floor(psiTorsionAngle / ” + binSize + “) + 180 as psiTorsionAngleBinIndex, ” + “count(*) as numberOfResidues”,”phiTorsionAngleBin, psiTorsionAngleBin”,new String[] {“phiTorsionAngleBin”, “psiTorsionAngleBin”, “phiTorsionAngleBinIndex”, “psiTorsionAngleBinIndex”, “n
Eduardo Born
java hibernate query syntax criteria
I’m having a hard time constructing a criteria query to get the “permissions” attribute from the Role entity with id = 2. The permission attribute is of Set type, so I’m creating a join and selecting from it, but the query fails with invalid grammar exception reporting “Unknown column ‘2L’ in ‘where clause'”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(“id”); // 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(“permissions”); PluralAttributePath pluralAttrPath = (PluralAttributePath)attributePath; PluralAttribute pluralAttr = pluralAttrPath.getAttribute();Join join = from.join((SetAttribute)pluralAttr);TypedQuery typedQuery = entityManager.createQuery(criteriaQuery.select(join)); return (List)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
b_gunay
java hibernate query criteria jpa-2.0
I’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=”([a-zA-Z0-9_\\s]+?|^$)”, message=”invalid filter”) 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(“siteAddress”), “%”+addressFilter.trim() + “%”)); }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 ‘generatedAlias0’ [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 ‘generatedAlias0’ [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
tirengarfio
Originally posted 2013-08-23 18:04:42.