日期:2014-05-17 浏览次数:20651 次
package basicCar.bean; import java.util.Date; public class BasicCar implements java.io.Serializable{ private long id; private String name; private String factory; private Date date; public BasicCar(){ } public BasicCar(String name,String factory,Date date){ this.name = name; this.factory = factory; this.date = date; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFactory() { return factory; } public void setFactory(String factory) { this.factory = factory; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } }
<hibernate-mapping> <class name="basicCar.bean.BasicCar" table="basiccar"> <id name="id" type="long" column="id" > <generator class="increment" /> </id> <property name="name" type="java.lang.String" column="name" /> <property name="factory" type="java.lang.String" column="factory" /> <property name="date" type="date" column="date" /> </class> </hibernate-mapping>
<hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.username">root</property> <property name="connection.password">1119</property> <property name="connection.url">jdbc:mysql://localhost:3306/car</property> <property name="show_sql">true</property> <mapping resource="basicCar/bean/BasicCar.hbm.xml" /> </session-factory> </hibernate-configuration>
package com.chuanjie56.util; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; public class HibernateSessionFactory { private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml"; @SuppressWarnings("unchecked") private static final ThreadLocal threadLocal = new ThreadLocal(); private static final Configuration cfg = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; @SuppressWarnings