0
votes

I have StudentGroup.class:

 package com.grades.model;

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.UniqueConstraint;

    @Entity
    @Table(name = "StudentGroup", uniqueConstraints = { @UniqueConstraint(columnNames = "group_number") })
    public class StudentGroup {

        @Id
        @GeneratedValue
        @Column(name = "id")
        private int id;
        @Column(name = "group_number")
        private int groupNumber;

        public StudentGroup() {

        }

        public StudentGroup(int groupNumber) {

            this.groupNumber = groupNumber;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getGroupNumber() {
            return groupNumber;
        }

        public void setGroupNumber(int groupNumber) {
            this.groupNumber = groupNumber;
        }

        @Override
        public String toString() {
            return "StudentGroup [id=" + id + ", groupNumber=" + groupNumber + "]";
        }
    }

In my database i have a table with name 'student_group' and when i try to insert a row with hibernate i got the following exception in Tomcat: SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/application] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.grades.model.StudentGroup]] with root cause com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'db.studentgroup' doesn't exist

Could anyone help me with this problem?

2
I've never used hibernate so I can't say for sure, but wouldn't "StudentGroup" vs "student_group" be a problem?Uueerdo

2 Answers

0
votes

This '@Table(name = "StudentGroup"' says your database table should be named 'StudentGroup' change the annotation or the table name accordingly.

0
votes

Your question states the table's name is 'student_group', but your code refers to a table named 'studentgroup' (no underscore).