Using JPQL(not HQL) with Hibernate -


i using jpa classes hibernate hence, making use of persistence.xml file database connectivity

i want delete multiple rows database hence created below code

entitymanager em = entitymanagerfactoryclass.getemf().createentitymanager(); try {     entitytransaction transaction = em.gettransaction();     transaction.begin();     query query = em.createquery("delete node o "          + "where o.building_name = :name , o.floor_no= :no");     query.setparameter("name", buildingname);     query.setparameter("no", floorno);     int deleted = query.executeupdate(); 

i following error

java.lang.illegalargumentexception: org.hibernate.hql.internal.ast.querysyntaxexception: node not mapped [delete node o o.building_name = :name , o.floor_no= :no] @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1374) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1310) @ org.hibernate.ejb.abstractentitymanagerimpl.createquery(abstractentitymanagerimpl.java:294) @ com.iitb.gise.evacuation.service.uploadnodepathservice.savenodedata(unknown source) @ com.iitb.gise.evacuation.pojo.dataobject.savenodes(unknown source) @ com.iitb.gise.evacuation.bean.imageretrivebean.savedata(unknown source) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.el.parser.astvalue.invoke(astvalue.java:278) @ org.apache.el.methodexpressionimpl.invoke(methodexpressionimpl.java:274) @ org.apache.myfaces.view.facelets.el.contextawaretagmethodexpression.invoke(contextawaretagmethodexpression.java:96) @ org.apache.myfaces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:72) @ javax.faces.component.uicommand.broadcast(uicommand.java:120) @ javax.faces.component.uiviewroot._broadcastall(uiviewroot.java:1013) @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:284) @ javax.faces.component.uiviewroot._process(uiviewroot.java:1302) @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:745) @ org.apache.myfaces.lifecycle.invokeapplicationexecutor.execute(invokeapplicationexecutor.java:38) @ org.apache.myfaces.lifecycle.lifecycleimpl.executephase(lifecycleimpl.java:170) @ org.apache.myfaces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:117) @ javax.faces.webapp.facesservlet.service(facesservlet.java:197) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1023) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:312) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source) 

i attaching below node.java file. contains annotations. need create mapping file?

import java.io.serializable;  import javax.persistence.column; import javax.persistence.embeddedid; import javax.persistence.entity; import javax.persistence.table;  import org.hibernate.annotations.type;  import com.vividsolutions.jts.geom.point;  @suppresswarnings("serial") @entity @table(name="node") public class node implements serializable{  @embeddedid nodeprimarykey nodeprimarykey; @column(name = "node_name") string nodename; @column(name = "node_capacity") int nodecapacity;  @type(type="org.hibernate.spatial.geometrytype") @column(name="node_location") point location; @column(name = "node_type") string nodetype;            //source or destination  //getters , setters } 

below compositekeyclass nodeprimarykey

@embeddable public class nodeprimarykey implements serializable {  private static final long serialversionuid = 1l; @column(name="building_name") string buildingname; @column(name="floor_no") int floorno; @column(name="node_id") string nodeid;     //getters , setters } 

persistence.xml file

<?xml version="1.0" encoding="utf-8"?> 

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> org.hibernate.ejb.hibernatepersistence

        <class>com.iitb.gise.evacuation.entity.node</class>         <class>com.iitb.gise.evacuation.entity.nodeprimarykey</class>     <properties>          <property name="hibernate.dialect" value="org.hibernate.dialect.postgresqldialect" />         <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test" />         <property name="hibernate.connection.driver_class" value="org.postgresql.driver" />         <property name="hibernate.connection.username" value="postgres" />         <property name="hibernate.connection.password" value="*****" />         <property name="hibernate.show_sql" value="true" />         <property name="hibernate.format_sql" value="true" />      </properties> </persistence-unit> </persistence> 

the error clear:

org.hibernate.hql.internal.ast.querysyntaxexception: node not mapped 

edit:
using @table name (node) , not @entity name node (the default simple class name); hql works entity, not physical table name.

use:

query query = em.createquery("delete node o " + "where o.building_name = :name , o.floor_no= :no"); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -