1

I am trying to connect to the database with hibernate using spring.

I am using IntelliJ IDEA.

I have created new spring project. Added hibernate framework to it and then :

View -> Tool Windows -> Persistance -> Right click on project -> Generate persistence mapping -> By database schema -> Choose data source ( added the database ) -> choosed package -> created hibernate.config.xml -> chosed entities to map -> ok

It has generated this hibernate.congif.xml file

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="connection.url">jdbc:mysql://localhost:3306/tornoci</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <mapping class="db.TorkoEntity"/>
      <!-- DB schema will be updated if needed -->
    <!-- <property name="hbm2ddl.auto">update</property> -->
  </session-factory>
</hibernate-configuration>

Now when i right click on persistance and chose console i type

from TorkoEntity

and run it it throws

[28000] Access denied for user 'matej'@'localhost' (using password: NO)

I was going step by step with this source yet i cannot figure out why is this happening , i tried to add

<property name="hibernate.connection.username">name</property>
<property name="hibernate.connection.password">passwd</property>

to the hibernate.config.xml file but it didnt help at all.

How can i make this work? All help is highly appreciated. Thanks

CrazyCoder
  • 350,772
  • 137
  • 894
  • 800
Darlyn
  • 4,152
  • 11
  • 30
  • 73
  • 1. Check that you can query the database using the same credentials form the Data Source you have assigned to the session factory. 2. Check that you have defined hibernate.config.xml file in the Hibernate facet for the module. 3. Please also check that the xml file contains DB credentials properties after generating persistence mappings as there could be [an issue](https://youtrack.jetbrains.com/issue/IDEA-154393#comment=27-1463678) with their deletion. – Andrey Mar 02 '17 at 09:04
  • Have you solved it yet? I am also having the same problem. – krismath Jun 11 '18 at 12:13

1 Answers1

0

The error you are encountering is from the mysql database rather than with the code. Most likely you need to give the "matej" user proper permissions in the db.

See MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

Community
  • 1
  • 1
David D
  • 107
  • 2
  • 8