First create a new MAVEN project, Pom.xml configured to
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>com.jinzhe</groupId> <artifactid>jinzhe </artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name >jinzhe</name> <url>http://maven.apache.org</url> <properties> < Project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies > <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <ver sion>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid >c3p0</groupId> <artifactId>c3p0</artifactId> <VERSION>0.9.1.2≪/version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifact Id>logback-classic</artifactid> <version>1.0.11</version> </dependency> <!--Hiberna Te 4.3.0 start--> <dependency> <groupId>org.hibernate</groupId> <artifactid>hibernate- core</artifactid> <version>4.3.5.Final</version> </dependency> <dependency> <gr Oupid>org.hibernate.javax.persistence</groupid> <artifactid>hibernate-jpa-2.1-api</artifactid > <version>1.0.0.Final</version> </dependency> <dependency> <groupid>org.hibern Ate.common</groupid> <artifactId>hibernate-commons-annotations</artifactId> <version>
4.0.4.final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactid>hibernate-c3p0</artIfactid> <version>4.3.5.Final</version> </dependency> <!--hibernate 4.3.0 end--> ;d ependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> &L
t;version>5.1.26-bin</version> </dependency> </dependencies> </project>
The Hibernate configuration is:
<! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://hibernate.so Urceforge.net/hibernate-configuration-3.0.dtd "> Then hibernate
Confuguration = new Configuration (). Configure ();
Standardserviceregistrybuilder builder = new Standardserviceregistrybuilder (). Applysettings ( Confuguration.getproperties ());
standardserviceregistry sr = Builder.build ();
Sessionfactory = Confuguration.buildsessionfactory (SR);
The test code invoked:
public static void Main (string[] args) {
System.out.println ("11111111");
Users user = new users ();
User.setname ("dddd");
User.setage (a);
Session s = hibernateservice.getsession ();
Transaction tx = S.begintransaction ();
S.save (user);
Tx.commit ();
S.close ();
}