0

I'm new to Spring JPA stuff. I'm learning now. I got weird error while trying to insert data in mysql database.

I made sure that I have a the table and database setup correctly as same as my

mysql> show columns in empolyee in test;


| Field | Type        | Null | Key | Default | Extra          |

| id    | int(6)      | NO   | PRI | NULL    | auto_increment | 
  eid   | int(6)      | YES  |     | NULL    |                |
| name  | varchar(40) | NO   |     | NULL    |                |
| role  | varchar(20) | YES  |     | NULL    |                |

My entity class:-

      @Entity
     public class Employee extends AbstractPersistable<Long> {

    private int eid;
    private String name;
    private String role;

    public Employee(){

    }

    public Employee(int aeid, String aname, String arole){
        eid=aeid;
        name = aname;
        role = arole;
       }
     }

Error:-

 HTTP Status 500 - Request processing failed; nested exception is  org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.SQLGrammarException: Table 'test.employee' doesn't exist; 
nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 
Table 'test.employee' doesn't exist
3
  • Maybe you are connected to an other database? Commented Nov 20, 2014 at 7:34
  • 2
    empolyee and Employee are not same? is it typo? Commented Nov 20, 2014 at 7:35
  • @Atilla Ozgur, you actually gave a right answer as a comment. I'd suggest you to post it as an answer. This is a typo: empolyee in DB and employee in java Commented Nov 20, 2014 at 7:43

3 Answers 3

1

Your table name in database is empolyee

@Entity
public class Employee extends AbstractPersistable<Long>

Here you are not specifying @Table annotation hence JPA will take table name as class name which is Employee which doesn't exist in your database. Hence change this

@Entity
@Table(name="empolyee")  //this exists in database
public class Employee extends AbstractPersistable<Long>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! It's working now. Jut a question why auto generated filed id always start from 6? I tried few others, always start from 6
0

Case sensitivity of MySQL table names depends on operating system:

In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive. However, Mac OS X also supports UFS volumes, which are case sensitive just as on any Unix.

So, you need to set table name in the correct case :

 @Entity @Table(name = "empolyee")
 public class Employee extends AbstractPersistable<Long>  { ... }

Comments

0

Change your entity class annotation to below.

@Entity
@Table(name="empolyee")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.