比如数据库中表为table.用hibernateTool生成pojo和hbm时,会产生一个 TableId.java和一个Table.java,为什么,
这时候如何插入数据,
Table.java:
public class Table implements java.io.Serializable {
private TableId id;
public Table() {
}
....
}
TableId.java中有数据库中表table 的实际属性,这时怎么操作,或者哪位提供个文档,我自己去看也行.
[b]问题补充:[/b]
Table里只有一个Id属性.
就算new一个,也一样,还是只有一个setId的方法,没有set其它属性的方法.
[b]问题补充:[/b]
首先对表示感谢.然后贴一下数据库设置.
bz_id char(1)
bz_name varchar(20)
idx smallint
CREATE TABLE [dbo].BZ NULL CONSTRAINT [DF_BZ_bz_id] DEFAULT (''),
[bz_name] varchar NULL CONSTRAINT [DF_BZ_bz_name] DEFAULT (''),
[idx] [smallint] NULL CONSTRAINT [DF_BZ_idx] DEFAULT (0)
) ON [PRIMARY]
里面没有设置主键.而且id和idx都允许空的,(因为业务要求不同,所以有两个ID.)
[b]问题补充:[/b]
下面是Bz.hbm.xml
[code="java"]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
[/code]
[b]问题补充:[/b]
Bz.java
[code="java"]
package org.gaodi.bean;
// Generated 2009-11-11 23:23:08 by Hibernate Tools 3.2.4.GA
/**
-
Bz generated by hbm2java
*/
public class Bz implements java.io.Serializable {private BzId id;
public Bz() {
}public Bz(BzId id) {
this.id = id;
}public BzId getId() {
return this.id;
}public void setId(BzId id) {
this.id = id;
}
}
[/code]
BzId.java
[code="java"]
package org.gaodi.bean;
// Generated 2009-11-11 23:23:08 by Hibernate Tools 3.2.4.GA
/**
-
BzId generated by hbm2java
*/
public class BzId implements java.io.Serializable {private Character bzId;
private String bzName;
private Short idx;public BzId() {
}public BzId(Character bzId, String bzName, Short idx) {
this.bzId = bzId;
this.bzName = bzName;
this.idx = idx;
}public Character getBzId() {
return this.bzId;
}public void setBzId(Character bzId) {
this.bzId = bzId;
}public String getBzName() {
return this.bzName;
}public void setBzName(String bzName) {
this.bzName = bzName;
}public Short getIdx() {
return this.idx;
}public void setIdx(Short idx) {
this.idx = idx;
}public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof BzId))
return false;
BzId castOther = (BzId) other;return ((this.getBzId() == castOther.getBzId()) || (this.getBzId() != null && castOther.getBzId() != null && this.getBzId().equals( castOther.getBzId()))) && ((this.getBzName() == castOther.getBzName()) || (this .getBzName() != null && castOther.getBzName() != null && this.getBzName() .equals(castOther.getBzName()))) && ((this.getIdx() == castOther.getIdx()) || (this.getIdx() != null && castOther.getIdx() != null && this.getIdx().equals( castOther.getIdx())));
}
public int hashCode() {
int result = 17;result = 37 * result + (getBzId() == null ? 0 : this.getBzId().hashCode()); result = 37 * result + (getBzName() == null ? 0 : this.getBzName().hashCode()); result = 37 * result + (getIdx() == null ? 0 : this.getIdx().hashCode()); return result;
}
}
[/code]