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

前端 未结 9 1923
误落风尘
误落风尘 2021-02-20 01:22

I am getting the following error when using Hibernate:

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

And I am using a datasource fo

相关标签:
9条回答
  • 2021-02-20 01:35

    The issue could be that you haven't installed the client library for the database you are trying to connect to.

    I have a Spring application that does not have a persistence.xml file and therefore no hibernate.dialect declaration.

    Once I installed the MySQL Connector/J client library the error went away.

    EDIT: I've also gotten this error when the database server wasn't running. Something that often happens now that I run my MySQL server through MAMP.

    0 讨论(0)
  • 2021-02-20 01:42

    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>
    
    0 讨论(0)
  • 2021-02-20 01:45

    Just encountered this issue. In my case it was the hibernate.dialect configuration.I added the following to SessionFatcory config in spring context file:

    <bean id="mySessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="annotatedClasses">
            <list>
                <value>com.testapp.service.geolocation.LocationData</value>
                <value>com.testapp.service.profiles.Profile</value>
            </list>
        </property>    
         <property name="hibernateProperties">
            <value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
        </property>
     </bean>
    
    0 讨论(0)
  • 2021-02-20 01:48

    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.

    0 讨论(0)
  • 2021-02-20 01:52

    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();
    
    0 讨论(0)
  • 2021-02-20 01:53

    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.

    0 讨论(0)
提交回复
热议问题