DB2 table: TEST has only one test field: name character (10)
Hibernate HBM file: test.hbm.xml
XML Version = "1.0"?>
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