日期:2014-05-17  浏览次数:20858 次

小弟不才,请教个有关hibernate多对一的问题。
被引用方是不是需要设置成ID?

小弟有文章、用户(ID、用户名、笔名)2个类。

希望发表文章的时候引用用户的用户名。

但报错。。。好像是这样:
 ognl.OgnlException: target is null for setProperty(null, "x", [Ljava.lang.String;@1a48515)…………

如果文章引用用户类的id就一切正常。

文章类配置:


<class name="com.caobug.bean.Archive" table="caobug_archives">
<id name="id" column="id" type="integer">
<generator class="increment"></generator>
</id>
<property name="title" type="string"></property>
<property name="body" type="text"></property>
<property name="updateDate" column="update_date" type="timestamp"></property>
<property name="publishDate" column="publish_date" type="timestamp"></property>
<property name="click" type="integer"></property>
<property name="description" type="string"></property>
<many-to-one name="catalog" column="catalog_id" cascade="persist"
lazy="false" not-found="ignore">
</many-to-one>
<many-to-one name="user" column="uid" cascade="persist"
lazy="false" not-found="ignore"></many-to-one>
</class>


用户:

<class name="com.caobug.bean.User" table="caobug_users">
<id name="id" column="id" type="integer">
<generator class="increment"></generator>
</id>
<property name="userid" type="string"></property>
<property name="username" type="string"></property>
<property name="password" type="string"></property>
</class>


文章如何引用 userid ?

------解决方案--------------------
我们一般都是在user那边配置一对多 然后会有个set 集合 这样  怎么引用都没问题了
------解决方案--------------------
引用:
Quote: 引用:

我们一般都是在user那边配置一对多 然后会有个set 集合 这样  怎么引用都没问题了

兄弟,感谢你百忙中抽出时间解答。我参考你说的试试,非常感谢!!

一对多,多对一哪种设置比较方便后期维护和扩展呢?


尽量用多对一吧