hibernate java.lang.IllegalArgumentException: object is not an instance of declaring class 问题 50

publicclassAddress{privateIntegeraddressId;privateStringaddressDetail;publicAddress()... public class Address
{
private Integer addressId;

private String addressDetail;

public Address(){

}

public Address(String addressDetail){

this.addressDetail=addressDetail;
}

public Integer getAddressId()
{
return addressId;
}

public void setAddressId(Integer addressId)
{
this.addressId = addressId;
}

public String getAddressDetail()
{
return addressDetail;
}

public void setAddressDetail(String addressDetail)
{
this.addressDetail = addressDetail;
}

}

<hibernate-mapping>
<class name="dao.Address" table="address_inf">
<id name="addressId" type="java.lang.Integer">
<column name="address_id"></column>
<generator class="native">
<param name="sequence">testsequence</param>
</generator>
</id>
<property name="addressDetail" type="java.lang.String">
<column name="addressDetail"></column>
</property>
</class>
</hibernate-mapping>

public class TestManytoOne
{
public static void main(String[] args)
{
Configuration conf = new Configuration().configure();
SessionFactory sf = conf.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Testtb user = new Testtb();
Address a = new Address("耶路撒冷");
user.setId("00000000001");
user.setName("ddddddddd");
user.setAddress(a.toString());
session.persist(user);//执行到这一步报的错
Address a2 = new Address("流沙河");
user.setAddress(a2.toString());
tx.commit();
session.close();

}

}

严重: IllegalArgumentException in class: dao.Address, getter method of property: addressId
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of dao.Address.addressId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3605)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3321)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:93)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:637)
展开
 我来答
匿名用户
2011-07-08
展开全部
<id name="addressId" type="java.lang.Integer">
<column name="address_id"></column>
<generator class="native">
<param name="sequence">testsequence</param>
</generator>
</id>
既然是配置一个Integer的值,为什么要用一个String类型的值?
还有就是和一楼的疑问一样,为什么要对Address a = new Address("耶路撒冷");中的a对象引用进行toString()方法呢?引用名.toString()你得到的结果将是 包名+类名+@十六进制的内存地址
止华灿031
2011-07-08 · 超过12用户采纳过TA的回答
知道答主
回答量:44
采纳率:0%
帮助的人:16.5万
展开全部
检查下dao包下的Address,的 addressId的getter
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
帐号已注销
2011-07-07 · TA获得超过1243个赞
知道小有建树答主
回答量:2126
采纳率:55%
帮助的人:664万
展开全部
a.toString()
Address 对象为什么要tostring
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式