So if I want to use my SQL query which is defined from an XML file ,what should I do?? I try to do by following steps :
1. Create a file Person.hbm.xml : <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <sql-query name="Person.SqlQuery"> <![CDATA[ delete from person where id = -2 ]]> </sql-query> </hibernate-mapping> 2. Add a mapping resource to hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping class="com.mycompany.app.model.User"/> <mapping class="com.mycompany.app.model.Role"/> <mapping class="com.mycompany.app.model.Person"/> <!-- Mapping files --> <mapping resource="Person.hbm.xml"/> </session-factory> </hibernate-configuration> 3. Create a class HibernateUtil : package com.mycompany.app.webapp.util; import java.sql.Statement; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { Session session; Statement st; Configuration config; public HibernateUtil(){ config = new Configuration().configure(); SessionFactory sessionFactory = config.buildSessionFactory(); session = sessionFactory.openSession(); } public Configuration getConfiguration(){ return config; } public Session getSession(){ return session; } } 4. And I call SQL query named Person.SqlQuery in class PersonAction.java like this : package com.mycompany.app.webapp.action; import com.opensymphony.xwork2.Preparable; import com.mycompany.app.service.PersonManager; import com.mycompany.app.model.Person; import com.mycompany.app.webapp.action.BaseAction; import java.util.List; import com.mycompany.app.webapp.util.HibernateUtil; import org.hibernate.Query; import org.hibernate.Session; public class PersonAction extends BaseAction implements Preparable { private PersonManager personManager; private List persons; private Person person; private Long id; private HibernateUtil hibernateUtil = new HibernateUtil(); [....] public String delete() { //personManager.remove(person.getId()); Session session = hibernateUtil.getSession(); Query query = session.getNamedQuery("User.SqlQuery"); query.executeUpdate(); saveMessage(getText("person.deleted")); return SUCCESS; } [....] } 5. Then I run application but some errors occur when I access Person List page : javax.servlet.ServletException: Unable to instantiate Action, com.mycompany.app.webapp.action.PersonAction, defined for 'persons' in namespace '/'Error creating bean with name 'com.mycompany.app.webapp.action.PersonAction': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.mycompany.app.webapp.action.PersonAction]: Constructor threw exception; nested exception is org.hibernate.MappingException: An AnnotationConfiguration instance is required to use - action - file:/E:/My%20Data/Projects/demo_7/target/classes/struts.xml:114:99 [...] I debug my application ,and it throws an exeption at line code : config = new Configuration().configure(); Can u help me solve this?? Thanks much! mraible wrote: > > Their are no SQL statements unless you're using iBATIS. Hibernate uses > HibernateTemplate to do most of its CRUD actions in AppFuse. > > http://source.appfuse.org/browse/appfuse/trunk/data/hibernate/src/main/java/org/appfuse/dao/hibernate/GenericDaoHibernate.java?r=trunk > > Matt > > On Tue, Apr 28, 2009 at 8:31 PM, Kenny Ha <vifaxoc...@yahoo.com> wrote: > >> >> Hi all, >> >> In a generated full-source Maven project, where can I find SQL query for >> method edit(), delete(),...?? >> >> Thanks! >> -- >> View this message in context: >> http://www.nabble.com/SQL-query---tp23289344s2369p23289344.html >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net >> For additional commands, e-mail: users-h...@appfuse.dev.java.net >> >> > > -- View this message in context: http://www.nabble.com/SQL-query---tp23289344s2369p23289867.html Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net For additional commands, e-mail: users-h...@appfuse.dev.java.net