This is great, thank you for your reply, so I moved forward and now getting an exception:
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of com.test.entity.model.user.User.id
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
at com.test.dao.user.UserDao.getUsers(UserDao.java:63)
Here is my User entity:
Code:
@Entity
@Indexed
@NamedQueries({
@NamedQuery(name = "user.getUsers", query = "select u from User u")
})
@Table(name = "user")
public class User {
private static final transient Logger LOG = LoggerFactory.getLogger(User.class);
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String id;
@Column(name = "first_name", nullable = false)
@Field(analyze = Analyze.NO)
private String firstName;
@Field(analyze = Analyze.NO)
@Column(name = "last_name", nullable = false)
private String lastName;
public User() {
}
public int compareTo(User o) {
return 0;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
Here is my UserDao
Code:
@Named
public class UserDao {
protected EntityManagerFactory emf = Persistence.createEntityManagerFactory("mongo-hibernate");
protected EntityManager entityManager = emf.createEntityManager();
public List<User> getUsers() {
TypedQuery<User> namedQuery = entityManager.createNamedQuery("user.getUsers", User.class);
return namedQuery.getResultList();
}
}