org.hibernate.exception.SQLGrammarException: could not extract ResultSet&

210 views Asked by At

I am trying update marks through a dialog box.but it is showing error.

This is my POJO class called Student, I have created one table for that to update marks.

@Entity
public class Student 
{
    @Id
    private int sid;
    @Column(length=10)
    private String sname;
    private int marks;
    @Version
    private int verson;
    public int getSid() {
        return sid;
    }
    public void setSid(int sid) {
        this.sid = sid;
    }
    public String getsname() {
        return sname;
    }
    public void setsname(String sName) {
        this.sname = sName;
    }
    public int getMarks() {
        return marks;
    }
    public void setMarks(int marks) {
        this.marks = marks;
    }
    public int getVerson() {
        return verson;
    }
    public void setVerson(int verson) {
        this.verson = verson;
    }

}

This is my main class

public class ClientOfUser1 {

    public static void main(String[] args) 
    {
    Configuration conf=new Configuration().configure("hibernate.cfg.xml");
    ServiceRegistry registry=new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
    SessionFactory factory=conf.buildSessionFactory(registry);
    Session session=factory.openSession();
    Transaction tx=session.beginTransaction();
    Student s=(Student)session.get(Student.class, 101);
    String str=JOptionPane.showInputDialog("enter marks of (User1)");
    int m= Integer.parseInt(str);
    s.setMarks(m);
    tx.commit();
    session.close();
    factory.close();
    }
}

When I'm trying to execute this, it is showing another error also the error is "STUDENT0_"."VERSON": invalid identifier

2

There are 2 answers

0
Sergey Sargsyan On

Try to put

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

in application.properties

Otherwise explicitly specify studaent table name and schema name with @Table annotation

@Table(schema="...", name="...")
3
Grzegorz Oledzki On

There's too little information in the question. Please put the full error message, the structure of your database table, etc.

But... I'll take a guess, you have a typo...

Here you're missing an I:

"STUDENT0_"."VERSON": invalid identifier

which comes from:

private int verson;

and respective setters/getters.

And I bet your database table has a column called VERSION.