问题描述
运行了半天报这个错误Exceptioninthread"main"org.springframework.orm.hibernate3.HibernateQueryException:unexpectedtoken:monearline1,column309[selectbrandfromcn.webstudio.bean.McurwDataCampaignBrandasbrandINNERJOINbrand.mcurwDataTeamasteamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModelsbamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModels.mcurwDataModelasmowhere1=1andteam.teamName=?andbrand.campaignEndTime>=?mo.amodelName=?andbrand.campaignStartTime<=?];nestedexceptionisorg.hibernate.hql.ast.QuerySyntaxException:unexpectedtoken:monearline1,column309[selectbrandfromcn.webstudio.bean.McurwDataCampaignBrandasbrandINNERJOINbrand.mcurwDataTeamasteamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModelsbamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModels.mcurwDataModelasmowhere1=1andteam.teamName=?andbrand.campaignEndTime>=?mo.amodelName=?andbrand.campaignStartTime<=?]atorg.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)atorg.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)atorg.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)atorg.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)atorg.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)atcn.webstudio.dao.impl.McurwDataCampaignBrandDaoImpl.findByPropertys(McurwDataCampaignBrandDaoImpl.java:229)atcn.webstudio.service.impl.CampaignServiceImpl.findByCondition(CampaignServiceImpl.java:150)atTest.Test.main(Test.java:28)Causedby:org.hibernate.hql.ast.QuerySyntaxException:unexpectedtoken:monearline1,column309[selectbrandfromcn.webstudio.bean.McurwDataCampaignBrandasbrandINNERJOINbrand.mcurwDataTeamasteamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModelsbamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModels.mcurwDataModelasmowhere1=1andteam.teamName=?andbrand.campaignEndTime>=?mo.amodelName=?andbrand.campaignStartTime<=?]atorg.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)atorg.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244)atorg.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)atorg.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)atorg.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)atorg.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)atorg.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)atorg.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)atorg.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)atorg.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)atorg.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:923)atorg.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)...5moreCausedby:line1:309:unexpectedtoken:moatorg.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:1038)atorg.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3422)atorg.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3200)atorg.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3082)atorg.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2802)atorg.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2667)atorg.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)atorg.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)atorg.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2341)atorg.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)atorg.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)atorg.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1858)atorg.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:454)atorg.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:708)atorg.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)atorg.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)atorg.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)...15more我这有4个表一个是车型活动表还有一个车型表一个车型表和活动表的中间表还有一个组表因为一个活动可以有多个车型我就弄了一个中间表中间表只有三个字段本表id,车型id(外键)和活动Id(外键)也就是活动表有一个主键中间表两个外键一个主键车型表一个主键还有一个组表没什么用我就不贴了活动类Xml<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--MappingfileautogeneratedbyMyEclipsePersistenceTools--><hibernate-mapping><classname="cn.webstudio.bean.McurwDataCampaignBrand"table="mcurw_data_campaign_brand"><idname="campaignId"type="java.lang.Integer"><columnname="campaign_id"/><generatorclass="identity"/></id><many-to-onename="mcurwDataTeam"class="cn.webstudio.bean.McurwDataTeam"fetch="select"lazy="false"><columnname="campaign_team_id"/></many-to-one><propertyname="campaignTeam"type="java.lang.Integer"><columnname="campaign_team"not-null="true"><comment>活动归属组的ID</comment></column></property><propertyname="campaignStartTime"type="java.lang.Long"><columnname="campaign_start_time"not-null="true"><comment>活动开始时间</comment></column></property><propertyname="campaignEndTime"type="java.lang.Long"><columnname="campaign_end_time"not-null="true"><comment>活动结束时间</comment></column></property><setname="mcurwRelationshipCampaignBrandAndModels"inverse="true"><key><columnname="brand_id"not-null="true"><comment>活动ID</comment></column></key><one-to-manyclass="cn.webstudio.bean.McurwRelationshipCampaignBrandAndModel"/></set></class></hibernate-mapping>
中间表xml<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--MappingfileautogeneratedbyMyEclipsePersistenceTools--><hibernate-mapping><classname="cn.webstudio.bean.McurwRelationshipCampaignBrandAndModel"table="mcurw_relationship_campaign_brand_and_model"><idname="campaignId"type="java.lang.Integer"><columnname="campaign_id"/><generatorclass="identity"/></id><many-to-onename="mcurwDataCampaignBrand"class="cn.webstudio.bean.McurwDataCampaignBrand"fetch="select"lazy="false"><columnname="brand_id"not-null="true"><comment>活动ID</comment></column></many-to-one><many-to-onename="mcurwDataModel"class="cn.webstudio.bean.McurwDataModel"fetch="select"lazy="false"><columnname="model_id"not-null="true"><comment>车型ID</comment></column></many-to-one></class></hibernate-mapping>
车型xml<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--MappingfileautogeneratedbyMyEclipsePersistenceTools--><hibernate-mapping><classname="cn.webstudio.bean.McurwDataModel"table="mcurw_data_model"><idname="modelId"type="java.lang.Integer"><columnname="model_id"/><generatorclass="identity"/></id><propertyname="modelName"type="java.lang.String"><columnname="model_name"not-null="true"/></property><setname="mcurwRelationshipCampaignBrandAndModels"inverse="true"lazy="false"><key><columnname="model_id"not-null="true"><comment>车型ID</comment></column></key><one-to-manyclass="cn.webstudio.bean.McurwRelationshipCampaignBrandAndModel"/></set><setname="mcurwDataCampaignProducts"inverse="true"lazy="false"><key><columnname="campaign_model_id"not-null="true"><comment>车型ID</comment></column></key><one-to-manyclass="cn.webstudio.bean.McurwDataCampaignProduct"/></set></class></hibernate-mapping>
我拼写了hql语句是这样的selectbrandfromMcurwDataCampaignBrandasbrandINNERJOINbrand.mcurwDataTeamasteamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModelsbamINNERJOINbrand.mcurwRelationshipCampaignBrandAndModels.mcurwDataModelasmowhere1=1andteam.teamName=?andbrand.campaignEndTime>=?mo.amodelName=?andbrand.campaignStartTime<=?请问这么写有问题么?我写了另一个跟这个差不多的是正确的,但是这个有一个跟那个不太一样.就是那个不需要中间表,这个有中间表的应该怎么操作。错误告诉我大概得意思是brand.mcurwRelationshipCampaignBrandAndModels.mcurwDataModelasmo这个mo它说是未知的请高手解答,在线等比较急
解决方案
解决方案二:
少了ON条件
解决方案三:
join是不需要no条件的吧?
解决方案四:
找到错误了
解决方案五:
他自己把on写成om了。
解决方案六:
学习了