Java – play frame JPA problems with save()

I'm trying to save a simple object in the database, but it gives me some problems

This is my object class:

@Entity
@Table(name="lines")
public class Line extends GenericModel{

    @Id
    @Column(name="line_id")
    private int id;

    @Column(name="line_text")
    private String text;

    @Column(name="line_postid")
    private int postid;

    @Column(name="line_position")
    private int position;
}

This is what I mean in the controller:

Line l = new Line();
l.setPosition(0);
l.setPostid(4);
l.setText("geen");
l.save();

I'm doing the same thing for other models. I don't have any problems. Only this one brings me problems When I refresh the browser, I get: persistenceexception: org hibernate. exception. Sqlgrammarexception: unable to perform JDBC batch update

I also added JPA. Com to my configuration Debugsql = true. In my console, I get:

Cause: Java sql. Batchupdateexception: there is an error in your SQL syntax; Check the manual corresponding to the version of MySQL server to use the correct syntax near the value (0,4, 'Geen', 0) 'of' lines (line_position, line_post, line_text, line_id) on line 1

The browser also shows that this exception has been recorded as ID 66k3glbb6, but I don't know where to view my log, so what if someone can tell me that?

Solution

Lines is a reserved word in MySQL. You need to escape it as follows:

@Table(name="`lines`") // Hibernate way

or

@Table(name="\"lines\"") // JPA standard way
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>