HibernateException:未设置“hibernate.dialect”时,对DialectResolutionInfo的访问不能为空
使用 maven 创建休眠测试项目。
当我运行项目时,它会生成异常:
org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.hibernatetest.App.main(App.java:33)
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.hibernatetest.App.main(App.java:51)
但是在主类中,必需的属性被设置了。不知道为什么程序是 genrAating 异常。
主要类别:
public class App {
public static void main(String[] args) {
Configuration configuration;
ServiceRegistry serviceRegistry;
SessionFactory sessionFactory;
Session session = null;
try {
configuration = new Configuration();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
configuration.setProperty("hibernate.dialect ", "com.applerao.hibernatesqlite.dialect.SQLiteDialect");
configuration.setProperty("hibernate.connection.url ", "jdbc:sqlite:TailorDB.db");
configuration.setProperty("hibernate.connection.driver_class ", "org.sqlite.JDBC");
configuration.setProperty("hibernate.connection.username ", "");
configuration.setProperty("hibernate.connection.password ", "");
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
session = sessionFactory.openSession();
CustomerModel c = new CustomerModel();
c.setID(5);
c.setNIC_Number("691201631345");
c.setFirstName("Zee");
c.setNumber("55225522");
c.setLastName("Jan");
c.setCustomerCode("Zee-123");
session.beginTransaction();
session.save(c);
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
} finally {
session.close();
}
}
}
在 POM 文件中:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>com.applerao</groupId>
<artifactId>hibernatesqlite</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
任何想法问题可能在哪里??
客户模型 cLass:
@Entity
@Table(name = "Customer")
public class CustomerModel {
@Id
@GeneratedValue
@Column(name = "c_id")
int ID;
@Column(name = "c_code")
String customerCode;
@Column(name = "c_fname")
String firstName;
@Column(name = "c_mname")
String middleName;
@Column(name = "c_lname")
String lastName;
@Column(name = "c_nic")
String NIC_Number;
@Column(name = "c_email")
String email;
@Column(name = "c_pnumber")
String number;
}