多的一方关键配置文件如下:
<set name="shops" inverse="true">
<key column="uid"></key>
<one-to-many class="Shop"/>
</set>
一的一方关键配置如下:
<many-to-one name="user" class="User" column="uid"></many-to-one>vo类里面各自都有对方的一个引用,这里我就不贴出来了。
生成的表的结构如下
user表
id   username   password
1     xxx         xxx
另外一个msg表
id   txt   uid
1     xxx   1
2     sss   1
其中uid是user表的引用
现在我想做的是,用户登陆后,向msg中插入数据,插入的时候uid也插入
关键代码如下:
this.getSession().save(msg);
action里面添加代码如下:
shopdaoimpl.addShop(shop);
这句话就是调用了this.getSession().save(msg);  保存就出问题了。
异常如下:
8:50:57,111 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: jsp.all.vo.User, getter method of property: id
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of jsp.all.vo.User.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)感觉好像是ID的问题,我在this.getSession().save(msg);的前面试着打印User的id,能正常获取到。方法如下:
System.out.println("第二个地方"+msg.getUser().getId());  此值经过观察,正常。求哪位高手指点一下,最有可能是什么原因造成的呢?????数据库mysql, 主键全自动递增。