Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d039d3

Browse files
committed
1.hibernate初探
2.maven03 archetype=generator生成3.wedemo web工程 jetty tomcat配置在pom.xml文件中
1 parentbce2bf3 commit3d039d3

File tree

50 files changed

+2226
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2226
-0
lines changed

‎Hibernate_001/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/target/

‎Hibernate_001/pom.xml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<projectxmlns="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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>Hibernate_001</groupId>
4+
<artifactId>Hibernate_001</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<build>
7+
<sourceDirectory>src</sourceDirectory>
8+
<testSourceDirectory>test</testSourceDirectory>
9+
<resources>
10+
<resource>
11+
<directory>src</directory>
12+
<excludes>
13+
<exclude>**/*.java</exclude>
14+
</excludes>
15+
</resource>
16+
</resources>
17+
<plugins>
18+
<plugin>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>3.1</version>
21+
<configuration>
22+
<source>1.6</source>
23+
<target>1.6</target>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.hibernate</groupId>
31+
<artifactId>hibernate-core</artifactId>
32+
<version>4.1.0.Final</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>junit</groupId>
36+
<artifactId>junit</artifactId>
37+
<version>4.10</version>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
</project>

‎Hibernate_001/src/Address.hbm.xml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPEhibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3+
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4+
<!-- Generated 2017-1-29 17:14:45 by Hibernate Tools 3.4.0.CR1-->
5+
<hibernate-mapping>
6+
<classname="Address"table="ADDRESS">
7+
<idname="postcode"type="java.lang.String">
8+
<columnname="POSTCODE" />
9+
<generatorclass="assigned" />
10+
</id>
11+
<propertyname="phone"type="java.lang.String">
12+
<columnname="PHONE" />
13+
</property>
14+
<propertyname="address"type="java.lang.String">
15+
<columnname="ADDRESS" />
16+
</property>
17+
</class>
18+
</hibernate-mapping>

‎Hibernate_001/src/Address.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
3+
4+
publicclassAddress {
5+
6+
privateStringpostcode;// Óʱà
7+
privateStringphone;// µç»°
8+
privateStringaddress;// µØÖ·
9+
10+
publicAddress () {
11+
12+
}
13+
14+
publicAddress(Stringpostcode,Stringphone,Stringaddress) {
15+
this.postcode =postcode;
16+
this.phone =phone;
17+
this.address =address;
18+
}
19+
20+
publicStringgetPostcode() {
21+
returnpostcode;
22+
}
23+
24+
publicvoidsetPostcode(Stringpostcode) {
25+
this.postcode =postcode;
26+
}
27+
28+
publicStringgetPhone() {
29+
returnphone;
30+
}
31+
32+
publicvoidsetPhone(Stringphone) {
33+
this.phone =phone;
34+
}
35+
36+
publicStringgetAddress() {
37+
returnaddress;
38+
}
39+
40+
publicvoidsetAddress(Stringaddress) {
41+
this.address =address;
42+
}
43+
44+
45+
}

‎Hibernate_001/src/Junior.hbm.xml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPEhibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3+
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4+
<!-- Generated 2017-1-29 17:14:45 by Hibernate Tools 3.4.0.CR1-->
5+
<hibernate-mapping>
6+
<classname="Junior"table="JUNIOR">
7+
<idname="sid"type="int">
8+
<columnname="SID" />
9+
<generatorclass="assigned" />
10+
</id>
11+
<propertyname="sname"type="java.lang.String">
12+
<columnname="SNAME" />
13+
</property>
14+
<propertyname="gender"type="java.lang.String">
15+
<columnname="GENDER" />
16+
</property>
17+
<propertyname="birthday"type="java.util.Date">
18+
<columnname="BIRTHDAY" />
19+
</property>
20+
<!--
21+
<many-to-one name="address" class="Address" fetch="join">
22+
<column name="ADDRESS" />
23+
</many-to-one>
24+
-->
25+
<componentname="address"class="Address">
26+
<propertyname="postcode"column="POSTCODE"></property>
27+
<propertyname="phone"column="phone"></property>
28+
<propertyname="address"column="address"></property>
29+
</component>
30+
</class>
31+
</hibernate-mapping>

‎Hibernate_001/src/Junior.java‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
importjava.util.Date;
2+
3+
publicclassJunior {
4+
// 1.公有的类
5+
// 2.提供公有的不带参数的默认的构造方法
6+
// 3.属性私有
7+
// 4.属性setter/getter封装
8+
9+
privateintsid;// 学号
10+
privateStringsname;// 姓名
11+
privateStringgender;// 性别
12+
privateDatebirthday;
13+
privateAddressaddress;
14+
15+
publicJunior() {
16+
17+
}
18+
19+
publicJunior(intsid,Stringsname,Stringgender,Datebirthday,
20+
Stringaddress) {
21+
// super();
22+
this.sid =sid;
23+
this.sname =sname;
24+
this.gender =gender;
25+
this.birthday =birthday;
26+
}
27+
28+
publicintgetSid() {
29+
returnsid;
30+
}
31+
32+
publicvoidsetSid(intsid) {
33+
this.sid =sid;
34+
}
35+
36+
publicStringgetSname() {
37+
returnsname;
38+
}
39+
40+
publicvoidsetSname(Stringsname) {
41+
this.sname =sname;
42+
}
43+
44+
publicStringgetGender() {
45+
returngender;
46+
}
47+
48+
publicvoidsetGender(Stringgender) {
49+
this.gender =gender;
50+
}
51+
52+
publicDategetBirthday() {
53+
returnbirthday;
54+
}
55+
56+
publicvoidsetBirthday(Datebirthday) {
57+
this.birthday =birthday;
58+
}
59+
60+
publicAddressgetAddress() {
61+
returnaddress;
62+
}
63+
64+
publicvoidsetAddress(Addressaddress) {
65+
this.address =address;
66+
}
67+
68+
@Override
69+
publicStringtoString() {
70+
return"Students [sid=" +sid +", sname=" +sname +", gender="
71+
+gender +", birthday=" +birthday +", address=" +address
72+
+"]";
73+
}
74+
}

‎Hibernate_001/src/Students.hbm.xml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPEhibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3+
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4+
<!-- Generated 2017-1-26 17:47:24 by Hibernate Tools 3.4.0.CR1-->
5+
<hibernate-mapping>
6+
<classname="Students"table="STUDENTS">
7+
<idname="sid"type="int">
8+
<columnname="SID" />
9+
<!--
10+
<generator class="assigned" />
11+
-->
12+
<generatorclass="native" />
13+
</id>
14+
<propertyname="sname"type="java.lang.String">
15+
<columnname="SNAME" />
16+
</property>
17+
<propertyname="gender"type="java.lang.String">
18+
<columnname="GENDER" />
19+
</property>
20+
<propertyname="birthday"type="java.util.Date">
21+
<columnname="BIRTHDAY" />
22+
</property>
23+
<propertyname="address"type="java.lang.String">
24+
<columnname="ADDRESS" />
25+
</property>
26+
</class>
27+
</hibernate-mapping>

‎Hibernate_001/src/Students.java‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
importjava.util.Date;
2+
3+
// 学生类
4+
5+
publicclassStudents {
6+
// 1.公有的类
7+
// 2.提供公有的不带参数的默认的构造方法
8+
// 3.属性私有
9+
// 4.属性setter/getter封装
10+
11+
privateintsid;// 学号
12+
privateStringsname;// 姓名
13+
privateStringgender;// 性别
14+
privateDatebirthday;
15+
privateStringaddress;
16+
17+
publicStudents() {
18+
19+
}
20+
21+
publicStudents(intsid,Stringsname,Stringgender,Datebirthday,
22+
Stringaddress) {
23+
// super();
24+
this.sid =sid;
25+
this.sname =sname;
26+
this.gender =gender;
27+
this.birthday =birthday;
28+
this.address =address;
29+
}
30+
31+
publicintgetSid() {
32+
returnsid;
33+
}
34+
35+
publicvoidsetSid(intsid) {
36+
this.sid =sid;
37+
}
38+
39+
publicStringgetSname() {
40+
returnsname;
41+
}
42+
43+
publicvoidsetSname(Stringsname) {
44+
this.sname =sname;
45+
}
46+
47+
publicStringgetGender() {
48+
returngender;
49+
}
50+
51+
publicvoidsetGender(Stringgender) {
52+
this.gender =gender;
53+
}
54+
55+
publicDategetBirthday() {
56+
returnbirthday;
57+
}
58+
59+
publicvoidsetBirthday(Datebirthday) {
60+
this.birthday =birthday;
61+
}
62+
63+
publicStringgetAddress() {
64+
returnaddress;
65+
}
66+
67+
publicvoidsetAddress(Stringaddress) {
68+
this.address =address;
69+
}
70+
71+
@Override
72+
publicStringtoString() {
73+
return"Students [sid=" +sid +", sname=" +sname +", gender="
74+
+gender +", birthday=" +birthday +", address=" +address
75+
+"]";
76+
}
77+
78+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPEhibernate-configuration PUBLIC
3+
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4+
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
5+
<hibernate-configuration>
6+
<session-factory>
7+
<propertyname="connection.username">root</property>
8+
<propertyname="connection.password">root</property>
9+
<propertyname="connection.driver_class">com.mysql.jdbc.Driver</property>
10+
<propertyname="connection.url">jdbc:mysql://localhost:3306/hibernate?useUnicode=true&amp;characterEncoding=UTF-8</property>
11+
<propertyname="dialect">org.hibernate.dialect.MySQLDialect</property>
12+
13+
<propertyname="show_sql">true</property>
14+
<propertyname="format_sql">true</property>
15+
<propertyname="hibernate.default_schema">hibernate</property>
16+
<propertyname="hbm2ddl.auto">create</property>
17+
<propertyname="hibernate.current_session_context_class">thread</property>
18+
19+
<mappingresource="Students.hbm.xml"/>
20+
<mappingresource="Junior.hbm.xml"/>
21+
</session-factory>
22+
</hibernate-configuration>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
importorg.hibernate.Session;
2+
importorg.hibernate.SessionFactory;
3+
importorg.hibernate.cfg.Configuration;
4+
importorg.hibernate.service.ServiceRegistry;
5+
importorg.hibernate.service.ServiceRegistryBuilder;
6+
importorg.junit.Test;
7+
8+
9+
publicclassSessionTest {
10+
11+
@Test
12+
publicvoidtestopenSession () {
13+
Configurationconfig =newConfiguration().configure();
14+
ServiceRegistryserviceRegistry =newServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
15+
SessionFactorysessionFactory =config.buildSessionFactory(serviceRegistry);
16+
Sessionsession =sessionFactory.openSession();
17+
if(session !=null) {
18+
System.out.println("session created successed!");
19+
}
20+
}
21+
22+
@Test
23+
publicvoidtestGetCurrentSession () {
24+
Configurationconfig =newConfiguration().configure();
25+
ServiceRegistryserviceRegistry =newServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
26+
SessionFactorysessionFactory =config.buildSessionFactory(serviceRegistry);
27+
Sessionsession =sessionFactory.getCurrentSession();// single
28+
if (session !=null) {
29+
System.out.println("session created successed11!");
30+
}else {
31+
System.out.println("session created failed!");
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp