Set set ing, which is equivalent to joining two tables and inserting data together

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.