日期:2014-05-20 浏览次数:20714 次
<class name="org.model.Customer" table="customers" lazy="false" dynamic-update="true" dynamic-insert="true" > <id name="id" type="java.lang.String" column="ID" > <generator class="uuid.hex" /> </id> <property name="name" type="java.lang.String" column="NAME" length="15" /> <property name="sex" type="java.lang.String" column="SEX" length="1" /> <property name="description" type="java.lang.String" column="DESCRIPTION" length="65535" /> <!-- Associations --> <!-- bi-directional one-to-many association to Order --> <set name="orders" lazy="true" inverse="true" cascade="all" > <key> <column name="CUSTOMER_ID" /> </key> <one-to-many class="org.model.Order" /> </set> </class>
package test; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.model.Customer; public class Test { private static SessionFactory sessionFactory; static{ sessionFactory = new Configuration().configure().buildSessionFactory(); } public void createNewCustomer(Customer c){ Session sess = sessionFactory.openSession(); Transaction tx = sess.beginTransaction(); sess.save(c); tx.commit(); } public void updateCustomer(Customer c ){ Session sess = sessionFactory.openSession(); Transaction tx = sess.beginTransaction(); sess.update(c); tx.commit(); } public static void main(String[] args) { Test t = new Test(); Customer c = new Customer(); c.setId("8a8482d51d18ec17011d18ec1a750001"); c.setDescription("sdfsdfdsfsdf"); t.updateCustomer(c); } }