问题
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