② Ing set attributes ②: array attributes

Source: Internet
Author: User

Hibernate. cfg. xml:

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.                   -->

Person. Java:

public class Person {private int id;private String name;private int age;private String[] schools;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String[] getSchools() {return schools;}public void setSchools(String[] schools) {this.schools = schools;}}

Person. HBM. xml:

<? XML version = "1.0"?> <! Doctype hibernate-mapping public "-// hibernate/hibernate DTD ing DTD 3.0 // en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

Test. Java:

Public class test {public static void main (string [] ARGs) {session = hibernatesessionfactory. getsession (); transaction TXT = session. begintransaction (); person p1 = new person (); p1.setname (""); p1.setage (18); string [] schools1 = new string [] {" ", "Junior High School", "Senior High School"}; p1.setschools (schools1); person P2 = new person (); p2.setname ("James"); p2.setage (22 ); string [] schools2 = new string [] {"", ""}; p2.setschools (schools2); Session. save (P1); Session. save (P2); TXT. commit (); hibernatesessionfactory. closesession ();}}

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.