'hibernate.dialect' must be set when no Co

2020-07-03 06:51发布

I am getting the following error when using Hibernate:

'hibernate.dialect' must be set when no Connection available

And I am using a datasource for database connection.

9条回答
你好瞎i
2楼-- · 2020-07-03 07:21

This error is hibernate doing a poor job of telling you what went wrong with your attempted connection with database.

In my case it was as simple as having a wrong password in config file.

查看更多
祖国的老花朵
3楼-- · 2020-07-03 07:25

In the Hibernate configuration dialog has a tab "options" it is possible to select some. In this case I was using Oracle Enterprise Pack for Eclipse that already had configured connector, but was still getting the error. Select an option on the list was enough to solve.

查看更多
萌系小妹纸
4楼-- · 2020-07-03 07:26

You need to set the property

hibernate.dialect

In the hibernate (persistence.xml or bean declaration) configuration, the value depends on your database, for example:

Postgres: org.hibernate.dialect.PostgreSQL82Dialect
Oracle: org.hibernate.dialect.Oracle10gDialect

All posible options are listen here

For example, a sample persistence.xml looks like:

<persistence-unit>
    ...
    <properties>
        ...
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        ...
    </properties>
</persistence-unit>
查看更多
戒情不戒烟
5楼-- · 2020-07-03 07:27

In some cases just using a wrong name for the database results in this Exception. Hibernate is apparently trying to determine the dialect before doing anything else, and as the DB cannot be reached, the error message comes from the part responsible for the dialect select. Bad error messaging on part of Hibernate.

查看更多
成全新的幸福
6楼-- · 2020-07-03 07:28

I had this problem too. The reason was missing <property name="dataSource" ref="dataSource" /> element in <bean id="sessionFactory"> definition.

查看更多
放我归山
7楼-- · 2020-07-03 07:29

You will get this issue even if you have your configuration files having proper value but you don't configure it in the code.

I was explaining hibernate, I forgot to use configure() before buildSessionFactory() so I was getting the error.

You might want to recheck it.

Previous code which was giving me error

SessionFactory factory = new Configuration().buildSessionFactory();

Changed code No Error

SessionFactory factory = new Configuration().configure().buildSessionFactory();
查看更多
登录 后发表回答