Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法删除java spring中的对象列表_Java_Spring - Fatal编程技术网

无法删除java spring中的对象列表

无法删除java spring中的对象列表,java,spring,Java,Spring,我的代码是: List<Session> futureSessions = this.getFutureSession(group.getSessions()); for (Session session: futureSessions) { Boolean exists = false; for (SessionDTO sessionDTO: groupDTO.getSessions()) { if (sess

我的代码是:

    List<Session> futureSessions = this.getFutureSession(group.getSessions());
    for (Session session: futureSessions) {
        Boolean exists = false;
        for (SessionDTO sessionDTO: groupDTO.getSessions()) {
            if (session.getId() == sessionDTO.getId()) {
                exists = true;
            }
        }

        if(false == exists) {
            // sessionService.delete(session);
            group.getSessions().remove(session);
        } else {
            exists = false;
        }
    }  Group groupUpdated = groupService.save(group);
List futureSessions=this.getFutureSession(group.getSessions());
用于(会议:未来会议){
布尔存在=假;
for(SessionDTO SessionDTO:groupDTO.getSessions()){
if(session.getId()==sessionDTO.getId()){
存在=真;
}
}
if(false==存在){
//sessionService.delete(会话);
group.getSessions().remove(会话);
}否则{
存在=假;
}
}Group groupUpdated=groupService.save(组);
这部分代码用于将对象(会话)删除到我的组对象中。我在angular和java之间使用JavaSpring进行dilog。 我在这两个对象之间有一个关系,在保存我的组对象之前,如果我的会话
groupServive.save(group)
我的会话未从数据库中删除,我会查找它。
任何帮助都将不胜感激

以下是我的团队模型:

`@实体 @表(name=“t_集团”) 公共类组实现可序列化{

private static final long serialVersionUID = 1L;

private Long id;
private String name;
private Boolean actif;
private Boolean deleted;
private Enterprise enterprise;
private String avatar;

private Date date_creation;
private Date date_update;
private Integer version;

private Set<User> users;
private List<Rule> rules;
private List<Session> sessions;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

@Column(nullable = false, unique = true)
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Column(nullable = false)
public Boolean getActif() {
    return actif;
}

public void setActif(Boolean actif) {
    this.actif = actif;
}

@Column(nullable = false)
public Boolean getDeleted() {
    return deleted;
}

public void setDeleted(Boolean deleted) {
    this.deleted = deleted;
}

@ManyToOne
@JoinColumn(name = "t_enterprise", nullable = true)
public Enterprise getEnterprise() {
    return enterprise;
}

public void setEnterprise(Enterprise enterprise) {
    this.enterprise = enterprise;
}

@Lob
@Column(columnDefinition = "LONGTEXT")
public String getAvatar() {
    return avatar;
}

public void setAvatar(String avatar) {
    this.avatar = avatar;
}

public Date getDate_creation() {
    return date_creation;
}

public void setDate_creation(Date date_creation) {
    this.date_creation = date_creation;
}

public Date getDate_update() {
    return date_update;
}

public void setDate_update(Date date_update) {
    this.date_update = date_update;
}

@ManyToMany
@JoinTable(name = "t_user_group", joinColumns = { 
        @JoinColumn(name = "t_group", nullable = false) }, 
        inverseJoinColumns = { @JoinColumn(name = "t_user") })
public Set<User> getUsers() {
    return users;
}

public void setUsers(Set<User> users) {
    this.users = users;
}

@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="group")
public List<Rule> getRules() {
    return rules;
}

public void setRules(List<Rule> rules) {
    this.rules = rules;
}

@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="group")
public List<Session> getSessions() {
    return sessions;
}

public void setSessions(List<Session> sessions) {
    this.sessions = sessions;
}

@Version
@Column(nullable = false)
public Integer getVersion() {
    return version;
}

public void setVersion(Integer version) {
    this.version = version;
}

public static long getSerialversionuid() {
    return serialVersionUID;
}

@PreUpdate
private void setLastUpdate() {
    this.setDate_update(new Date());
}

@PrePersist
private void setFirstCreationDate() {
    this.setLastUpdate();
    if(null == this.getDate_creation()){
        this.setDate_creation(new Date());
    }
}
private static final long serialVersionUID=1L;
私人长id;
私有字符串名称;
私有布尔活动;
删除私有布尔值;
私营企业;
私有字符串化身;
私人日期创建;
私人日期更新;
私有整数版本;
私人用户;
私人名单规则;
非公开名单会议;
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
@列(nullable=false,unique=true)
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
@列(nullable=false)
公共布尔getActif(){
返回活动;
}
公共void setActif(布尔actif){
this.actif=actif;
}
@列(nullable=false)
公共布尔getDeleted(){
返回已删除;
}
公共无效集已删除(布尔值已删除){
this.deleted=已删除;
}
@许多酮
@JoinColumn(name=“t_enterprise”,nullable=true)
公共企业{
回归企业;
}
公共企业(企业){
这个企业=企业;
}
@高球
@列(columnDefinition=“LONGTEXT”)
公共字符串getAvatar(){
返回化身;
}
公共虚拟化身(字符串化身){
this.avatar=化身;
}
公共日期getDate_创建(){
创建返回日期;
}
公共无效设置日期创建(创建日期){
this.date\u creation=创建日期;
}
公共日期getDate_update(){
返回日期更新;
}
公共无效设置日期更新(日期更新){
this.date\u update=date\u update;
}
@许多
@JoinTable(name=“t\u user\u group”,joinColumns={
@JoinColumn(name=“t_group”,nullable=false)},
inverseJoinColumns={@JoinColumn(name=“t_user”)})
公共集getUsers(){
返回用户;
}
公共void集合用户(集合用户){
this.users=用户;
}
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy=“group”)
公共列表getRules(){
退货规则;
}
公共无效集合规则(列表规则){
这个。规则=规则;
}
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy=“group”)
公共列表getSessions(){
返回会议;
}
公共会话(列表会话){
这个。会话=会话;
}
@版本
@列(nullable=false)
公共整数getVersion(){
返回版本;
}
公共void setVersion(整数版本){
this.version=版本;
}
公共静态长GetSerialVersionId(){
返回serialVersionId;
}
@预更新
私有void setLastUpdate(){
此.setDate_更新(新日期());
}
@预科生
私有无效setFirstCreationDate(){
this.setLastUpdate();
if(null==this.getDate_creation()){
此.setDate_创建(new Date());
}
}

`

好的,解决方案只是在我的会话中添加一个方法

`


会话
,它是您创建为DTO的对象,还是在hibernate中创建的会话,您的问题似乎与Angular无关,您遇到了什么错误?
@Override
public void delete(Session session) {
    // repository.delete(session);
    if (session.getId() > 0) {

        query = em.createNativeQuery("DELETE FROM `t_session` WHERE `id` = :t_session", Session.class);
        query.setParameter("t_session", session.getId());
        query.executeUpdate();
    }
}`