Pojo class
Package com. qiujy. domain;
Import java. util. Set;
Public class student {
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 set <string> gethobbes (){
Return Hobbes;
}
Public void sethobbes (set <string> Hobbes ){
This. Hobbes = Hobbes;
}
Private long ID; // ID of the Object ID OID
Private string name; // name
Private set <string> Hobbes; // personal interests
Public student () {}// No parameter Constructor
}
Configuration File
<? 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>
<Hibernate-mapping>
<Class name = "com. qiujy. domain. Student" table = "student">
<ID name = "ID" column = "ID" type = "long">
<Generator class = "native"/>
</ID>
<Property name = "name" not-null = "true"/>
<! --
The Set element is used to map attributes of the Java. util. Set type.
Name attribute: name of the property to be mapped
Table attribute: Specifies the name of the corresponding database table.
-->
<Set name = "Hobbes" table = "student_holobby">
<! -- Key sub-element: Specifies the foreign key column of the table corresponding to the set attribute -->
<Key column = "student_id"/>
<! -- Element sub-element: ing elements in the set -->
<Element type = "string" column = "hobby_name" not-null = "true"/>
</Set>
</Class>
</Hibernate-mapping>
Test page
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Page import = "com. Main. teststudent" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
Teststudent Stu = new teststudent ();
Stu. getstudent ();
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> my JSP 'student. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>
<Body>
This is my JSP page. <br>
</Body>
</Html>