| <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.url">jdbc:hsqldb:hsql://localhost</property> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.username">sa</property> <property name="connection.password"></property> <property name="dialect">net.sf.hibernate.dialect.HSQLDialect</property> <property name="hibernate.show_sql">false</property> <mapping resource="Cat.hbm.xml"/> </session-factory> </hibernate-configuration> |
| import junit.framework.TestCase; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.Transaction; import net.sf.hibernate.cfg.Configuration; public class CatTest extends TestCase { private Session session; private Transaction tx; protected void setUp() throws Exception { Configuration cfg = new Configuration().configure();////注意这一行,这是本文重点讨论研究的地方。 session = cfg.buildSessionFactory().openSession(); tx = session.beginTransaction(); } protected void tearDown() throws Exception { tx.commit(); session.close(); } public void testCreate() { //请在此方法内添加相关的代码,本文不讨论怎么样使用Hibernate API。 } public void testUpdate() { //请在此方法内添加相关的代码,本文不讨论怎么样使用Hibernate API。 } public void testDelete() { //请在此方法内添加相关的代码,本文不讨论怎么样使用Hibernate API。 } public void testQuery() { //请在此方法内添加相关的代码,本文不讨论怎么样使用Hibernate API。 } } |
| Configuration cfg = new Configuration().configure(); |
| <property name="connection.url">jdbc:hsqldb:hsql://localhost</property> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.username">sa</property> <property name="connection.password"></property> <property name="dialect">net.sf.hibernate.dialect.HSQLDialect</property> |
| hibernate.dialect net.sf.hibernate.dialect.HSQLDialect hibernate.connection.driver_class org.hsqldb.jdbcDriver hibernate.connection.username sa hibernate.connection.password hibernate.connection.url jdbc:hsqldb:hsql://localhost |
| <mapping> <jcs-class-cache> <jcs-collection-cache> <collection-cache> |
| <mapping resource="Cat.hbm.xml"/> |