CRUD module Play! 1.2.4

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:49:23

问题


I'm developing a webapp with Play! Framework (1.2.4). I've import CRUD module successfully, and connected a MySQL DB with JDBC.I've created a model like this:

@Entity

public class MyEntity extends Model {

    @Id
    @GeneratedValue (strategy=GenerationType.IDENTITY)
    public int id;

    public String name;
    public String phone;
    public String web;
    public String address;

    public MyEntity (String name, String phone, String web, String address) {
        this.name=name;
        this.phone=phone;
        this.web=web;
        this.address=address;
    }
}

In localhost:9000/admin, in Administration CRUD default panel, I try to Add a new object of MyEntity, doesn't works:

PersistenceException occured : org.hibernate.exception.GenericJDBCException: could not insert: [models.MyEntity]

LogFail: object.save() (around line 152)

In my MySQL DB i have a table called MyEntity with 5 fields:

id INT (PK, NotNull, AUTO_INCREMENT);  
name VARCHAR;  
phone INT;  
web VARCHAR;  
address VARCHAR

Don't know why it doesn't works. I know JPA uses an autogenerated id field, but i want that autogenerated id will be MyEntity id field.

Log said:

[...]Caused by: java.sql.SQLException: Field 'id' doesn't have a default value.  

Any idea about this?


回答1:


Model already has an Id.

If you want to use your own Id then you should extend GenericModel instead.



来源:https://stackoverflow.com/questions/15053253/crud-module-play-1-2-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!