The <SQL-Insert>, <SQL-Update>, and <SQL-delete> labels are added to the hibernate ing file of hibernate 3, you can use SQL in these three tags to customize your insert, update, and delete actions, that is, when storing, updating, or deleting data. For example:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<class name="onlyfun.caterpillar.User" table="user">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.lang.String"/>
<property name="age" column="age" type="java.lang.Integer"/>
<sql-insert>
INSERT INTO user (name, age) VALUES (?, ?)
</sql-insert>
<sql-update>
UPDATE user SET name=?, age=?, WHERE id=?
</sql-update>
<sql-delete>
DELETE FROM user WHERE id=?
</sql-delete>
</class>
? The corresponding order is the order in which attributes appear in the ing file. Assume that you store the object: Session = sessionfactory. opensession ();
Tx = session. begintransaction ();
Session. Save (User );
TX. Commit ();
Session. Close ();
The SQL statement displayed in the execution result will be your custom statement, instead of the statement automatically generated by hibernate:
Hibernate: Insert into user (name, age) values (?, ?)
|