gpt4 book ai didi

java - 在 Hibernate 中删除日期集合

转载 作者:行者123 更新时间:2023-12-02 04:58:50 26 4
gpt4 key购买 nike

当时间表列表满足我的要求时,我想从数据库中删除 CinemaProgramme。当我尝试删除cinemaProgramme 时,出现异常,因为列表中存在外键,所以无法删除它。我听说过“OneToMany 和 OneToOne 注释和 XML 上的 orphanRemoval 选项。孤立删除将确保从数据库中删除不再从关系中引用的任何对象。”但我无法使用它,因为我有一个 elementcollection 映射而不是 onetomany 等。

所以我尝试先删除列表,然后删除 CinemaProgramme,但是当尝试执行时:

String hql1 = "delete CinemaProgramme.timetable as p where p in (:list)";
Query q1 = session.createQuery(hql1);
q1.setParameterList("list", q.list());
q1.executeUpdate();

我遇到异常org.hibernate.hql.ast.QuerySyntaxException:CinemaProgramme.timetable 未映射。我花了几个小时来解决这个问题:(

CinemaProgramme 类:

   @Entity
@Table(name = "cinema_programme")
public class CinemaProgramme implements Serializable {

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private int id;

@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name = "programme_id")
private List<Date> timetable;

@ManyToOne(cascade= CascadeType.ALL,fetch = FetchType.EAGER)
@JoinColumn(name = "movie_id")
private Movie movie;

@Column(name = "dubbing")
private boolean dubbing;
}

......编辑 用于:

String hql1 = "delete CinemaProgramme as p where p.timetable in (:list)";
Query q1 = session.createQuery(hql1);
List d = q.list();
q1.setParameterList("list", d);
System.out.println(d); - displays [2015-02-01 00:00:00.0]
我得到:......

7772 [http-bio-8080-exec-3] ERROR org.hibernate.util.JDBCExceptionReporter - No value specified for parameter 
dContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2513)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2489)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2336)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:101)
... 46 more

最佳答案

认为您的查询必须String hql1 = "delete CinemaProgramme as p where p.timetable in (:list)";

关于java - 在 Hibernate 中删除日期集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499244/

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