2

Hi all i am new to playframework and JPA

1st i created a User entity bean as below

@Entity

@Table(name="m_users")

public class AppUser {

@Id
    @GeneratedValue 
public  int uid;

@Required
@MaxSize(100)
public @Column(name="user_name") String userName;

@Required
@MaxSize(20)
public @Column(name="pass") String password;

public AppUser(int uid, String userName, String password) {
    this.uid = uid;
    this.userName = userName;
    this.password = password;
}
}

then i created a datamanager that saves the content in to the in memory of playframework as shown below

public class DataManager extends JapidController {
    public static void cuser() {

        AppUser user = new AppUser();
        user.password = "secret";
        user.userName = "jonathan@gmail.com";      
        user.save();
        renderJapid(user);
    }
}

Following error is what i am getting

PersistenceException occured : org.hibernate.PropertyAccessException: could not set a field value by reflection setter of models.AppUser.uid

play.exceptions.JavaExecutionException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of models.AppUser.uid

Community
  • 1
  • 1
K Nikhil
  • 23
  • 3

2 Answers2

1

It sounds like Hibernate is looking for a setter for your uid property. Have you provided this setter or were you just planning to provide direct access to a public property?

Alex Barnes
  • 7,174
  • 1
  • 30
  • 50
1

Your AppUSer class should look something like this:

@Entity
@Table(name = "m_users")
public class AppUser extends Model {

    @Required
    @MaxSize(100)
    public @Column(name = "user_name")
    String userName;

    @Required
    @MaxSize(20)
    public @Column(name = "pass")
    String password;

    public AppUser(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

}

As you see, it should extends Model, which already implements generated id value.

You can read more about that here.

PrimosK
  • 13,848
  • 10
  • 60
  • 78
  • In the situation if I have another class say message where i need reference to from user and to user. ??? – K Nikhil Dec 28 '11 at 06:17
  • Look at the Post class on the page mentioned in above answer and give attention to @ManyToOne annotation.... – PrimosK Dec 28 '11 at 14:51
  • @PrimosK I have a similar problem. Are you willing to help me with it? Here is the link: http://stackoverflow.com/questions/25295695/could-not-set-a-field-value-by-reflection-setter – CodeMed Aug 13 '14 at 20:59