-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Select using mySQL: Unknown column
PostPosted: Thu Feb 24, 2011 10:25 am 
Newbie

Joined: Thu Feb 24, 2011 10:02 am
Posts: 5
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


Top
 Profile  
 
 Post subject: Re: Select using mySQL: Unknown column
PostPosted: Thu Feb 24, 2011 10:36 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should not have annotations on both the 'id' field and the 'getId()' method.


Top
 Profile  
 
 Post subject: Re: Select using mySQL: Unknown column
PostPosted: Thu Feb 24, 2011 10:52 am 
Newbie

Joined: Thu Feb 24, 2011 10:02 am
Posts: 5
nordborg wrote:
You should not have annotations on both the 'id' field and the 'getId()' method.


Pretty simple...

THX!!!

Now it works fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.