配置此令牌后预期的标识符

时间:2016-05-19 09:58:41

标签: hibernate

我正在构建我的第一个hibernate应用程序,所以我在configure中遇到错误。这是我的代码

package firsthibernate;




import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

import com.fasterxml.classmate.AnnotationConfiguration;


public class mnapp {


    Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(
            configuration.getProperties()). build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;









    }
}

    so, In the above code, this line (configuration.configure();) gives me error (configure Identifier expected after this token.).

我怎么解决?

我的其他代码如下:

这是我的hibernate.cfg.xml。

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE hibernate-configuration PUBLIC  
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  

          <hibernate-configuration>  

    <session-factory>  
        <property name="hbm2ddl.auto">create</property>  
        <property name="dialect">org.hibernate.dialect.MysqlDialect</property>  
        <property name="connection.url">jdbc:mysql://localhost:3306/db</property>  
        <property name="connection.username">root</property>  
        <property name="connection.password">yellow1</property>  
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>  

    </session-factory>  

</hibernate-configuration>  

这是我的Employee.java

package firsthibernate;

import javax.persistence.*;


@Entity
@Table(name = "EMPLOYEE")
public class Employee {

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


    @Column(name = "first_name")
     private String firstName;


    @Column(name = "last_name")
    private String lastName;


    @Column(name = "salary")
    private int salary;

     public Employee() {}


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




       public String getFirstName() {
              return firstName;
           }
           public void setFirstName( String first_name ) {
              this.firstName = first_name;
           }




           public String getLastName() {
                  return lastName;
               }
               public void setLastName( String last_name ) {
                  this.lastName = last_name;
               }


               public int getSalary() {
                      return salary;
                   }
                   public void setSalary( int salary ) {
                      this.salary = salary;
                   }
                }

那我怎么能解决这个错误呢?

0 个答案:

没有答案