我有这个我无法解决的问题,这是我的实体类:
/** * @hibernate.class * table="users.network_topic" * @hibernate.cache usage="read-write" */ 公共类 NetworkTopic 实现 Serializable, Idable{
/** identifier field */
private Long id;
/** persistent field */
private Long networkId;
/** persistent field */
private Long topicId;
private UserTopic topic;
private Network network;
/**
* @hibernate.id
* generator-class="assigned"
* type="java.lang.Long"
* column="id"
*/
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* @hibernate.property
* type="java.lang.Long"
* column="network_id"
* not-null="true"
*/
public Long getNetworkId() {
return networkId;
}
public void setNetworkId(Long networkId) {
this.networkId = networkId;
}
/**
* @hibernate.property
* type="java.lang.Long"
* column="user_topic_id"
* not-null="true"
*/
public Long getTopicId() {
return topicId;
}
public void setTopicId(Long topicId) {
this.topicId = topicId;
}
/**
* @hibernate.set
* lazy="true"
* inverse="true"
* cascade="none"
* @hibernate.key
* column="user_topic_id"
* @hibernate.one-to-many
* class="com.netblue.matchpoint.domain.UserTopic"
*
*/
public UserTopic getTopic() {
return topic;
}
public void setTopic(UserTopic topic) {
this.topic = topic;
}
/**
* @hibernate.set
* lazy="true"
* inverse="true"
* cascade="none"
* @hibernate.key
* column="network_id"
* @hibernate.one-to-many
* class="com.netblue.matchpoint.domain.Network"
*
*/
public Network getNetwork() {
return network;
}
public void setNetwork(Network network) {
this.network = network;
}
@Override
public String toString() {
return "Network[id=" + id + "]";
}
}
然后我尝试用这个代码保存一个新的寄存器:
UserTopic topic = new UserTopic();
topic.setId(topicId);
topic.setName(ParseUtil.getString(map.get(MPConstants.TOPIC_NAME_PARAM)));
topic.setCreatedBy(ParseUtil.getInt(map.get(MPConstants.USER_ID)));
Date now = new Date();
topic.setCreatedDt(now);
topic.setLastUpdatedDt(now);
topic.setStatusId(Status.ACTIVE);
topic.setActivityCnt(0);
userTopicDao.saveOrUpdate(topic);
UserTopicMap utm = new UserTopicMap();
utm.setId(topicId);
utm.setMtid(topicId);
utm.setOtid(topicId);
utm.setIsDeleted(false);
utm.setLastUpdatedDt(now);
userTopicMapDao.saveOrUpdate(utm);
Network network = MpAuctionUtil.getNetworkById(networkId);
NetworkTopic networkTopic = new NetworkTopic();
networkTopic.setNetworkId(networkId);
networkTopic.setTopicId(topicId);
networkTopic.setNetwork(network);
networkTopic.setTopic(topic);
LOG.debug("userTopicService addObjSubscriber x networkId="+networkId+", topicId="+topicId);
networkTopicDao.saveOrUpdate(networkTopic);
最后几行是失败的,如果我删除它们它可以工作,我的意思是它可以保存主题,但是当我尝试这样做时它失败了,我不知道我是否做错了什么,请帮助我! !