У меня возникают проблемы при попытке удалить запись в моей таблице базы данных.
Структура базы данных следующая:
User ---< UserET >--- ExitTicket
ExitTicket.java
@Entity
@Table(name = "exit_ticket")
public class ExitTicketEntry implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String title;
private String dateET;
private Set<UserET> userETs= new HashSet<UserET>();
public ExitTicketEntry() {}
public ExitTicketEntry(String title,String dateET) {
this.title = title;
this.dateET = dateET;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY )
@Column(name = "ticket_id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany(mappedBy = "exitTicketEntry", orphanRemoval=true)
public Set<UserET> getUserETs() {
return userETs;
}
public void setUserETs(Set<UserET> userETs) {
this.userETs = userETs;
}
public void addUserETs(UserET userETs) {
this.userETs.add(userETs);
}
//getters and setters
}
UserET.java
@Entity
@Table(name="userET")
public class UserET implements Serializable {
//private static final long serialVersionUID = 1L;
private long answerId;
private User user;
private ExitTicketEntry exitTicketEntry;
private String answer;
private Date dateAnswer;
@Id
@GeneratedValue
@Column(name="answerId")
public long getAnswerId() {
return answerId;
}
public void setAnswerId(long answerId) {
this.answerId = answerId;
}
@ManyToOne(cascade = CascadeType.ALL )
@JoinColumn(name = "user_id")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ticket_id")
public ExitTicketEntry getExitTicketEntry() {
return exitTicketEntry;
}
public void setExitTicketEntry(ExitTicketEntry exitTicketEntry) {
this.exitTicketEntry = exitTicketEntry;
}
@Column(name = "answer")
public String getAnswer(){
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
@Column(name = "dateAnswer")
@Temporal(TemporalType.DATE)
public Date getDateAnswer() {
return dateAnswer;
}
public void setDateAnswer(Date dateAnswer) {
this.dateAnswer = dateAnswer;
}
User.java
@Entity
@Table(name="USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String user_name, user_password, user_type,user_realname;
private Set<UserET> userETs= new HashSet<UserET>();
public User() {
}
public User(String user_name,String user_password,String user_type,String user_realname) {
this.user_name = user_name;
this.user_password = user_password;
this.user_type = user_type;
this.user_realname=user_realname;
}
public void addExitTicketEntry(UserET group) {
this.userETs.add(group);
}
@Id
@GeneratedValue
@Column(name="user_id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany(mappedBy = "user", orphanRemoval=true)
public Set<UserET> getUserETs() {
return userETs;
}
public void setUserETs(Set<UserET> userETs) {
this.userETs = userETs;
}
public void addUserETs(UserET userETs) {
this.userETs.add(userETs);
} ... + getters and setters
Я могу правильно вставить новый Entry
из ExitTicket
(используя ExitTicketService.java) с помощью этой функции:
public void addEntryET(ExitTicketEntry exitTicketEntry) {
log.info("adding entry in database");
try {
hibernateTemplate.save(exitTicketEntry);
}
catch(Exception e) {
log.info("error adding an entry in the database->"+e.toString());
}
}
Однако, когда я пытаюсь удалить запись из таблицы базы данных, удаление из спящего режима выполняет только команды «выбор» и никогда не выполняет «удаление»
2018-11-05 09:28:27 INFO AuthService:72 - entro 1 ------
Hibernate: select exitticket0_.ticket_id as ticket_i1_0_0_, exitticket0_.dateET as dateET2_0_0_, exitticket0_.title as title3_0_0_ from exit_ticket exitticket0_ where exitticket0_.ticket_id=?
Mon Nov 05 09:28:27 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2018-11-05 09:28:27 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [9]
2018-11-05 09:28:27 TRACE BasicExtractor:61 - extracted value ([dateET2_0_0_] : [VARCHAR]) - [2011-05-20]
2018-11-05 09:28:27 TRACE BasicExtractor:61 - extracted value ([title3_0_0_] : [VARCHAR]) - [test1]
2018-11-05 09:28:27 TRACE CollectionType:790 - Created collection wrapper: [com.jcg.spring.hibernate.pojo.ExitTicketEntry.userETs#9]
Hibernate: select userets0_.ticket_id as ticket_i4_2_0_, userets0_.answerId as answerId1_2_0_, userets0_.answerId as answerId1_2_1_, userets0_.answer as answer2_2_1_, userets0_.dateAnswer as dateAnsw3_2_1_, userets0_.ticket_id as ticket_i4_2_1_, userets0_.user_id as user_id5_2_1_, user1_.user_id as user_id1_1_2_, user1_.user_name as user_nam2_1_2_, user1_.user_password as user_pas3_1_2_, user1_.user_realname as user_rea4_1_2_, user1_.user_type as user_typ5_1_2_ from userET userets0_ left outer join USER user1_ on userets0_.user_id=user1_.user_id where userets0_.ticket_id=?
2018-11-05 09:28:27 TRACE BasicBinder:65 - binding parameter [1] as [BIGINT] - [9]
2018-11-05 09:28:27 INFO AuthService:99 - deleted entry with ID#=9
Моя функция удаления в классе обслуживания:
public void deleteById(Class<?> type, long id) {
log.info("entro 1 ------");
ExitTicketEntry e=(ExitTicketEntry) hibernateTemplate.load(type,id);
hibernateTemplate.delete(e);
}
Я читал много форумов, но все еще имею ту же проблему, я не могу удалить записи. Я что-то упустил?