How to update data using a sleep request that has a parent property in where where

I am working on a java web application using hibernate and oracle. I set two objects like this

    @Entity
    public class Student{
    @Id
    Long id;
    String name;
    }

    @Entity
    public class Exam{
    @Id
    Long id;
    String status;
    @ManyToOne
    Student student;
    }

When I use select query in sleep mode, for example

    String hql="from Exam exam where exam.student.name=:name"

It works fine, but when I use the update request in sleep mode, for example

    String hql="update Exam exam set status=:status where exam.student.name=:name"

It causes the following error

    org.hibernate.exception.SQLGrammarException: ORA-00971: missing SET keyword

at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy154.executeUpdate(Unknown Source)
at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:413)
at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282)
at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1267)
at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116)

Am I doing something wrong?

0
source share
3 answers

Check if you have getters and setters.
Also use annotation @Columnif the name is in the database:

@Entity
    public class Student{
    @Id
    Long id;
    @Column(name="studentName")
    String name;
    }

" ", , @Transient, : http://docs.oracle.com/javaee/5/api/javax/persistence/Transient.html

+1

.

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html#batch-direct

, , HQL. where-where, .

, ,

    String hql = "update Exam exam set exam.status=:status where exam.id in(select e.id from Exam e where e.student.name=:name)"
+1

.

Query q = session.createQuery("from Exam exam where exam.student.name=:name"); q.setParameter("name", "xyz");
Exam exam = (Exam)q.list().get(0);

exam. status ("completed");
session.update (exam);

Use this if you are sure you are getting one and only one remodeled for upgrade. in other ways you can use this for your requirement

0
source

All Articles