Seffel
Seffel

Reputation: 397

unexpected end of subtree exception after Hibernate version update on delete query

I get a strange exception when I delete all data from a table. The exception occurs since I updated the Hibernate version from 3.x.x to 4.2.6.

the Dao method that I call to delete the data from the table:

  @Override
  public void deleteAll()
  {
     EntityManager em = getEntityManager();
     em.createQuery( "DELETE Document" ).executeUpdate();
  }

Stacktrace:

12:46:03,570 ERROR ErrorCounter:50 - <AST>:0:0: unexpected end of subtree
<AST>:0:0: unexpected end of subtree
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.whereClauseExpr(SqlGeneratorBase.java:1378)
at org.hibernate.hql.internal.antlr.SqlGeneratorBase.whereClause(SqlGeneratorBase.java:1272)
at org.hibernate.hql.internal.ast.exec.DeleteExecutor.<init>(DeleteExecutor.java:72)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.buildAppropriateStatementExecutor(QueryTranslatorImpl.java:535)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:201)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
at sun.reflect.GeneratedMethodAccessor800.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

Entity:

@Entity
@Table( name = "document" )
public class Document implements Serializable
{
  @Override
  @Id
  @GeneratedValue( strategy = GenerationType.IDENTITY )
  @Column( name = "document_id" )
  private int           id;

  private String                 filename;

  @Temporal( TemporalType.TIMESTAMP )
  @Column( name = "file_modified_time" )
  private Date                   fileModifiedTime;

  @ManyToOne( fetch = FetchType.LAZY )
  @JoinColumn( name = "attached_to_Task_fk" )
  private Task       attachedToTaskFk;

 //Getter/Setter
}

When I add a where clause to the delete query, the exception doesn't occur.

em.createQuery( "DELETE Document d WHERE d.id > 0" ).executeUpdate();

But I don't think that Hibernate intended it this way.

I already checked following topics:

Has anyone any idea how to fix this?

Upvotes: 3

Views: 6577

Answers (1)

Erik Pilz
Erik Pilz

Reputation: 4026

This appears to be a Hibernate bug that is fixed in 4.2.7 and 4.3.0.Beta5. The DeleteExecutor previously required a Where clause.

You can find the patch on GitHub if you're not ready to upgrade to 4.2.7.

Upvotes: 1

Related Questions