Hibernate's operation on the owner table

zhaozj2021-02-12  204

DB2 table: TEST has only one test field: name character (10)

Hibernate HBM file: test.hbm.xml

Test.java

Import java.io.serializable;

Public Class Test Implements Serializable {

Private testpk testpk; public void settestpk (Testpk value) {this.testpk = value;} public testpk gettestpk () {return this.testpk;}}

Testpk.java

Import java.io.serializable;

public class Testpk implements Serializable {private String name; public String getName () {return this.name;} public void setName (String value) {this.name = value;} public boolean equals (Object other) {Testpk that = (Testpk ) other; return this.name.equals (this.name);} / ** * returns the hash code for the key. * / public int.com (this.name.hashcode ());}

}

Test code:

Test T = new test (); testpk tpk = new testpk (); tpk.setname ("test000000"); T.Settestpk (TPK); session.save (t);

Finally, it is worth noting that when it is to be loaded, it is not possible to simply describe SESSION (TEST.CLASS, TEST000000 "); use a TestPK as an identifier of an entity class.

So should you write:

Testpk TPK = new testpk (); tpk.setname ("test000000"); test t = (test) session.load (Test.class, TPK);

Environment DB2, EclipiPise, Hibernate2 test success

转载请注明原文地址:https://www.9cbs.com/read-7054.html

New Post(0)