我在做关于新闻发布的一个功能!现在的问题是我的用户表和新闻表式1对多的关系.我想在插入新闻的时候同时向我的新闻表里插入我当前登录的用户,这个用户就是当前新闻的发布人! 不知道在影射文件那里怎么设置!
我的新闻影射文件时这样的:
<hibernate-mapping>
<class name="com.gcxj.entity.News" table="news" catalog="gcxj">
<id name="newsId" type="java.lang.Integer">
<column name="news_id" />
<generator class="increment" />
</id>
<many-to-one name="user" class="com.gcxj.entity.User" fetch="select">
<column name="account" length="20" not-null="true" />
</many-to-one>
<property name="newsTitle" type="java.lang.String">
<column name="news_title" length="100" not-null="true" />
</property>
<property name="newsContent" type="java.lang.String">
<column name="news_content" length="2000" not-null="true" />
</property>
<property name="publishDate" type="java.util.Date">
<column name="publish_date" length="0" />
</property>
</class>
</hibernate-mapping>我的用户影射文件是这样的:
<hibernate-mapping>
<class name="com.gcxj.entity.User" table="user" catalog="gcxj">
<id name="account" type="java.lang.String">
<column name="account" length="20" />
<generator class="assigned" />
</id>
<property name="password" type="java.lang.String">
<column name="password" length="20" not-null="true" />
</property>
<property name="role" type="java.lang.Integer">
<column name="role" />
</property>
<property name="logDate" type="java.util.Date">
<column name="log_date" length="0" />
</property>
<set name="newses" inverse="true">
<key>
<column name="account" length="20" not-null="true" />
</key>
<one-to-many class="com.gcxj.entity.News" />
</set>
</class>
</hibernate-mapping>
请各位帮帮忙
我的新闻影射文件时这样的:
<hibernate-mapping>
<class name="com.gcxj.entity.News" table="news" catalog="gcxj">
<id name="newsId" type="java.lang.Integer">
<column name="news_id" />
<generator class="increment" />
</id>
<many-to-one name="user" class="com.gcxj.entity.User" fetch="select">
<column name="account" length="20" not-null="true" />
</many-to-one>
<property name="newsTitle" type="java.lang.String">
<column name="news_title" length="100" not-null="true" />
</property>
<property name="newsContent" type="java.lang.String">
<column name="news_content" length="2000" not-null="true" />
</property>
<property name="publishDate" type="java.util.Date">
<column name="publish_date" length="0" />
</property>
</class>
</hibernate-mapping>我的用户影射文件是这样的:
<hibernate-mapping>
<class name="com.gcxj.entity.User" table="user" catalog="gcxj">
<id name="account" type="java.lang.String">
<column name="account" length="20" />
<generator class="assigned" />
</id>
<property name="password" type="java.lang.String">
<column name="password" length="20" not-null="true" />
</property>
<property name="role" type="java.lang.Integer">
<column name="role" />
</property>
<property name="logDate" type="java.util.Date">
<column name="log_date" length="0" />
</property>
<set name="newses" inverse="true">
<key>
<column name="account" length="20" not-null="true" />
</key>
<one-to-many class="com.gcxj.entity.News" />
</set>
</class>
</hibernate-mapping>
请各位帮帮忙
解决方案 »
- 彩信接口开发者请进。
- 为什么ActionForm为空,Struts1.2
- java执行copy
- 关于<jsp:userbean>与<jsp:setproperty>那些郁闷的事
- PO 后查询问题
- hibernate连接数据困问题。java.lang.NullPointerException。
- 请教各位大哥前辈牛人们!!严重救命中~~~
- Servlet action is currently unavailable(Servlet的行动是当前不可用)
- 会xdoclet的来一下,关于merge
- BMP里开发一个JavaBean来作为助手Bean错误提示:找不到jndi?
- 当下考SUN公司的SCJP有用吗?考过SCJP的人请留下脚印,百分感谢!!!
- 关于spring中的困惑?
设置下级联就行了吧