Could not find a getter for id
场景:Could not find a getter for id in class 的异常
Could not find a getter for id in class 的错误!
本人用 eclipse3.2+myeclipse5.1GA+hibernate3.0连接oracle写clob字段:
数据库中的表(content)中有两个字段:id(int),content(clob),
生成bean文件时:有两个文件产生了:content.java和contentid.java
和Content.hbm.xml
content.java
package cn.fusion.beans;
/**
* Content generated by MyEclipse - Hibernate Tools
*/
public class Content implements java.io.Serializable {
// Fields
private ContentId id;
// Constructors
/** default constructor */
public Content() {
}
/** full constructor */
public Content(ContentId id) {
this.id = id;
}
// Property accessors
public ContentId getId() {
return this.id;
}
public void setId(ContentId id) {
this.id = id;
}
}
-----------------
contentid.java
package cn.fusion.beans;
/**
* ContentId generated by MyEclipse - Hibernate Tools
*/
public class ContentId implements java.io.Serializable {
// Fields
private Long id;
private String content;
// Constructors
/** default constructor */
public ContentId() {
}
/** minimal constructor */
public ContentId(Long id) {
this.id = id;
}
/** full constructor */
public ContentId(Long id, String content) {
this.id = id;
this.content = content;
}
// Property accessors
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return this.content;
} public void setContent(String content) {
this.content = content;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof ContentId) ) return false;
ContentId castOther = ( ContentId ) other;
return ( (this.getId()==castOther.getId()) || ( this.getId()!=null && castOther.getId()!=null && this.getId().equals(castOther.getId()) ) )
&& ( (this.getContent()==castOther.getContent()) || ( this.getContent()!=null && castOther.getContent()!=null && this.getContent().equals(castOther.getContent()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getId() == null ? 0 : this.getId().hashCode() );
result = 37 * result + ( getContent() == null ? 0 : this.getContent().hashCode() );
return result;
}
}
--------------------------------
Content.hbm.xml
Content.hbm.xml
<?xml version= "1.0 " encoding= "utf-8 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "cn.fusion.beans.Content " table= "CONTENT " schema= "TZGA ">
<composite-id name= "id " class= "cn.fusion.beans.ContentId ">
<key-property name= "id " type= "java.lang.Long ">
<column name= "ID " precision= "22 " scale= "0 " />
</key-property>
<key-property name= "content " type= "java.lang.String ">
<column name= "CONTENT " />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
我前几次成表bean文件时都是只有一个java文件的,这次一下生成两个了,觉得有点奇怪,那两个高底怎么使用,用平时的方法到提示Could not find a getter for id in class....请高手帮忙啊:::
------解决方案--------------------
找不到get方法啊
------解决方案--------------------
表没有主键,用工具生成之前建个主键先
------解决方案--------------------
could not find a getter for ... in class ... 异常的解决2007年08月31日 星期五 11:26在spring+hibernate框架的java项目开发过程中,经常会遇到这样的错误:
could not find a getter for ... in class ...
可能原因如下:
1.真的没有写getter方法(发生几率:1%)
2.*.hmb.xml文件中的属性名和pojo不一致(*.hbm.xml和*.java没衔接好,不一致),字段属性没有正确配置,比如,*.hmb.xml中*.java的地址要明确(明确指出引用包的完整路径);映射错误;有多个主键时,对生成的联合主键配置错误;拼写错误(包括多空格)等(发生几率:48%)
3.方法写错/方法名写错,要按照javabean的书写规范写啊,要不然打死也找不到哪儿错了(发生几率:50%)
这里提一下:get/set是不是不允许方法名中有连续两个大写字母,例如
public String getODPType(){
return this.oDPType;
}
public void setODPType(String oDPType){
this.oDPType = oDPType;
}
这样写它就会报错,报找不到getter for oDPType的错误,但下面这样写就可以了
public String odpType;
public String getOdpType(){
return this.odpType;
}
public void setOdpType(String odpType){
this.odpType = odpType;
}
4.其他不明原因(发生几率:1%)
Could not find a getter for id in class 的错误!
本人用 eclipse3.2+myeclipse5.1GA+hibernate3.0连接oracle写clob字段:
数据库中的表(content)中有两个字段:id(int),content(clob),
生成bean文件时:有两个文件产生了:content.java和contentid.java
和Content.hbm.xml
content.java
package cn.fusion.beans;
/**
* Content generated by MyEclipse - Hibernate Tools
*/
public class Content implements java.io.Serializable {
// Fields
private ContentId id;
// Constructors
/** default constructor */
public Content() {
}
/** full constructor */
public Content(ContentId id) {
this.id = id;
}
// Property accessors
public ContentId getId() {
return this.id;
}
public void setId(ContentId id) {
this.id = id;
}
}
-----------------
contentid.java
package cn.fusion.beans;
/**
* ContentId generated by MyEclipse - Hibernate Tools
*/
public class ContentId implements java.io.Serializable {
// Fields
private Long id;
private String content;
// Constructors
/** default constructor */
public ContentId() {
}
/** minimal constructor */
public ContentId(Long id) {
this.id = id;
}
/** full constructor */
public ContentId(Long id, String content) {
this.id = id;
this.content = content;
}
// Property accessors
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return this.content;
} public void setContent(String content) {
this.content = content;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof ContentId) ) return false;
ContentId castOther = ( ContentId ) other;
return ( (this.getId()==castOther.getId()) || ( this.getId()!=null && castOther.getId()!=null && this.getId().equals(castOther.getId()) ) )
&& ( (this.getContent()==castOther.getContent()) || ( this.getContent()!=null && castOther.getContent()!=null && this.getContent().equals(castOther.getContent()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getId() == null ? 0 : this.getId().hashCode() );
result = 37 * result + ( getContent() == null ? 0 : this.getContent().hashCode() );
return result;
}
}
--------------------------------
Content.hbm.xml
Content.hbm.xml
<?xml version= "1.0 " encoding= "utf-8 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "cn.fusion.beans.Content " table= "CONTENT " schema= "TZGA ">
<composite-id name= "id " class= "cn.fusion.beans.ContentId ">
<key-property name= "id " type= "java.lang.Long ">
<column name= "ID " precision= "22 " scale= "0 " />
</key-property>
<key-property name= "content " type= "java.lang.String ">
<column name= "CONTENT " />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
我前几次成表bean文件时都是只有一个java文件的,这次一下生成两个了,觉得有点奇怪,那两个高底怎么使用,用平时的方法到提示Could not find a getter for id in class....请高手帮忙啊:::
------解决方案--------------------
找不到get方法啊
------解决方案--------------------
表没有主键,用工具生成之前建个主键先
------解决方案--------------------
could not find a getter for ... in class ... 异常的解决2007年08月31日 星期五 11:26在spring+hibernate框架的java项目开发过程中,经常会遇到这样的错误:
could not find a getter for ... in class ...
可能原因如下:
1.真的没有写getter方法(发生几率:1%)
2.*.hmb.xml文件中的属性名和pojo不一致(*.hbm.xml和*.java没衔接好,不一致),字段属性没有正确配置,比如,*.hmb.xml中*.java的地址要明确(明确指出引用包的完整路径);映射错误;有多个主键时,对生成的联合主键配置错误;拼写错误(包括多空格)等(发生几率:48%)
3.方法写错/方法名写错,要按照javabean的书写规范写啊,要不然打死也找不到哪儿错了(发生几率:50%)
这里提一下:get/set是不是不允许方法名中有连续两个大写字母,例如
public String getODPType(){
return this.oDPType;
}
public void setODPType(String oDPType){
this.oDPType = oDPType;
}
这样写它就会报错,报找不到getter for oDPType的错误,但下面这样写就可以了
public String odpType;
public String getOdpType(){
return this.odpType;
}
public void setOdpType(String odpType){
this.odpType = odpType;
}
4.其他不明原因(发生几率:1%)