我正在尝试检索表的元数据信息;我成功检索了表中的列和列类型。我也想检索每个列的大小。我对 Hibernate 还很陌生,并且一直坚持这一点。这就是我检索列名和类型的方式:
String[] columns = HibernateUtil.getSessionFactory()
.getClassMetadata(Java.class).getPropertyNames();
Type[] columnsType = HibernateUtil.getSessionFactory()
.getClassMetadata(Java.class).getPropertyTypes();
实体类:
@Entity
@Table(name="Box")
public class Box implements Serializable {
private int dimHeight;
private int dimLen;
private int dimWidth;
private double weight;
public Box() {
}
public int getDimHeight() {
return this.dimHeight;
}
public void setDimHeight(int dimHeight) {
this.dimHeight = dimHeight;
}
public int getDimLen() {
return this.dimLen;
}
public void setDimLen(int dimLen) {
this.dimLen = dimLen;
}
public int getDimWidth() {
return this.dimWidth;
}
public void setDimWidth(int dimWidth) {
this.dimWidth = dimWidth;
}
public double getWeight() {
return this.weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
}
代码和异常是:
Field foo = Box.class.getField("dimWidth");
foo.setAccessible(true);
java.lang.NoSuchFieldException: dimWidth
at java.lang.Class.getField(Class.java:1520)