gpt4 book ai didi

java - hibernate 插入错误: ids for this class must be manually assigned before calling save():

转载 作者:行者123 更新时间:2023-12-01 05:08:59 25 4
gpt4 key购买 nike

我有这个问题无法解决,这是我的实体类:

/** * @hibernate.class * 表=“用户.network_topic” * @hibernate.cache 用法=“读写”*/公共(public)类 NetworkTopic 实现 Serialized、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);

最后几行是失败的,如果我删除它们它可以工作,我的意思是它可以保存主题,但是当我尝试这样做时它失败了,我不知道我是否做错了什么,拜托帮助我!!

最佳答案

尚未为 NetworkTopic 类分配 ID。您必须使用 setId 方法或考虑其他 id 策略之一

2.2.3.1. Generating the identifier property

关于java - hibernate 插入错误: ids for this class must be manually assigned before calling save():,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12305343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com