Results 1 to 2 of 2
  1. #1
    ShinTec's Avatar
    ShinTec is offline Member
    Join Date
    Jan 2010
    Posts
    51
    Rep Power
    0

    Exclamation getting could not resolve property exception

    Hi Forum
    Im trying to get a specfic employee from the database using an id number. Im using Hibernates
    Criteria Class to do this

    heres my code
    Java Code:
     @SuppressWarnings("unchecked")
      //testing to see if i can get a specfic employee
      //using the session.createCriteria
      public List<Employee> getEmpRestrictList()
      {
    	  String idNum = "3";
    	  Session session = HibernateUtil.getSession();
    	
    	 //getting a list of employee 
    	  List cats = session.createCriteria(Employee.class).add(Restrictions.eq
    			  ("emp_id",idNum)).list();
    	 
    	 session.close();
    	 
    	 return cats;
      }
    ===============================
    main
    ===============================
    EmployeeManager em = new EmployeeManager();
    		
    		List<Employee> empList = em.getEmpRestrictList();
    		
    		for(Employee e : empList)
    		{
    			System.out.printf("%s\n",e.toString());
    		}

    this is the exception that is thrown
    Java Code:
    Exception in thread "main" org.hibernate.QueryException: could not resolve property: emp_id of: com.TimeKeeperExpress.model.Employee
    	at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)
    	at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:61)
    	at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1392)
    	at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
    Can anyone tell me whats wrong
    cant seem to figure it out :confused:
    Any help would be much appreciated and thank you in advance

  2. #2
    ShinTec's Avatar
    ShinTec is offline Member
    Join Date
    Jan 2010
    Posts
    51
    Rep Power
    0

    Default

    Oh figure it out instead of using Restriction.eq you use Restriction.idEq
    here an update on code

    Java Code:
     @SuppressWarnings("unchecked")
      //testing to see if i can get a specfic employee
      //using the session.createCriteria
      public List<Employee> getEmpRestrictList()
      {
    	  String idNum = "3";
    	  int anIdVal = Integer.parseInt(idNum);
    	  Session session = HibernateUtil.getSession();
    	
    	 //getting a list of employee 
    	  Criterion crit = Restrictions.idEq(new Integer(2));
    	  List cats = session.createCriteria(Employee.class).add(crit)
    	  .list();
    	 
    	 session.close();
    	 
    	 return cats;
      }
    hopes this helps every one

Similar Threads

  1. Replies: 0
    Last Post: 06-25-2009, 05:28 AM
  2. Yet another Cannot Resolve Symbol
    By Gabinka in forum New To Java
    Replies: 5
    Last Post: 03-27-2009, 10:28 PM
  3. Replies: 1
    Last Post: 11-03-2008, 06:16 PM
  4. Replies: 3
    Last Post: 04-07-2008, 05:56 PM
  5. Error: cannot resolve symbol, help me
    By mathias in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-06-2007, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •