I have a table in my MySQL database for which I am creating a new Model class extending from play.db.jpa.Model class.
Since the table already exists, I annotated the class mapping the table-name and primary key to an existing column:
@Entity
@Table(name="biz_companies")public class BizCompany extends Model {
@Id
public long biz_id; public String name;
public String street;
public String state;
public int zip;
public String phone;
public BizCompany() {
}
public BizCompany(long graphite_id, String name, String street,
String state, int zip, String phone) {
super();
this.graphite_id = graphite_id;
this.name = name;
this.street = street;
this.state = state;
this.zip = zip;
this.phone = phone;
}
}
However, when I try to load some data from data.yml file for this table through a JUnit test, I get an error.
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of
models.BizCompany.id
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1389)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1323)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:845)
at play.db.jpa.JPABase._save(JPABase.java:31)
at play.test.Fixtures.loadModels(Fixtures.java:221)
Any idea why this might be happening. If I remove the "@Id" annotation and run the test, it works fine but adds a new column to the table "id" which it assigns as the primary key.
I looked through the Play Model documentation but did not find an explanation. Any help would be appreciated.
Thanks