Hello,
I'm pretty new user of Hibernate and I guess it's a very simple question, but I could't find an answer :(
I'm trying to use Hybernate with a mySQL database.
I've got a User class:
Code:
@Entity(name = "user")
@Table(name = "user")
public class ShopUser {
@Id
@Column(name = "user_id")
private Long Id;
@Column(name = "firstname")
private String firstName;
@Column(name = "secondname")
private String secondName;
@Column(name = "password")
private String password;
// getter and setter for all members
@Id
@GeneratedValue
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
}
I created new database entries based on this class successfully, so all table-/column-mappings seem to be ok...
Now I want to read the data from this table:
Code:
public class UserOverviewTag extends BodyTagSupport {
@PersistenceContext
private EntityManager entityManager;
// ...
List<ShopUser> getUserList(){
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
CriteriaBuilder criteriaBuilder = entityManagerFactory.getCriteriaBuilder();
CriteriaQuery<ShopUser> criteriaQuery = criteriaBuilder.createQuery(ShopUser.class);
Root<ShopUser> root = criteriaQuery.from(ShopUser.class);
criteriaQuery.select(root);
Query query = entityManager.createQuery(criteriaQuery);
List<ShopUser> result = (List<ShopUser>)query.getResultList();
return result;
}
}
Quote:
02:53:30,325 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Shop].[jsp]] Servlet.service() for servlet jsp threw exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shopuser0_.id' in 'field list'
If you need the whole stacktrace or any further information, let me know...
If I use:
Code:
Query query = entityManager.createQuery("select s from user s");
I'm getting the same Exception.
I'm not sure, if it is important, but I'm using JTA.
What is missing to execute a query on my table successfully?
Thank you for your help,
glotzich