1

i am new to hibernate . and I am getting error like hibernate.properties not found and Access denied for user 'root'@'localhost' (using password: YES)

I am using MySqlWorkbench version 5.7.19 and hibernate version 5.2.6.Final jdk 1.8 with eclipse oxygen

this is my hibernate.cfg.xml file

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">gary@1234</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hbm2ddl.auto">update</property>
</session-factory>

and here is pom.xml

  <dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.6.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
    </dependency>

and here is my code

public class App {
public static void main(String[] args) {
    Alien alien = new Alien();
    alien.setAid(101);
    alien.setAname("pawan");
    alien.setColor("purple");
    Configuration con = new Configuration().configure();
    SessionFactory sf = con.buildSessionFactory();
    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();
    session.save(alien);
    tx.commit();
}}

and this is pojo class

public class Alien {

@Id
private int aid;
private String aname;
private String color;

public int getAid() {
    return aid;
}

public void setAid(int aid) {
    this.aid = aid;
}

public String getAname() {
    return aname;
}

public void setAname(String aname) {
    this.aname = aname;
}

public String getColor() {
    return color;
}

public void setColor(String color) {
    this.color = color;
}

}

10
  • 1
    Are you sure your database user is 'root' and your password is 'gary@1234'? Commented Aug 16, 2017 at 9:31
  • yes other application without hibernate is working fine on same Commented Aug 16, 2017 at 9:31
  • 1
    Where did you place your hibernate.cfg.xml file? Commented Aug 16, 2017 at 9:32
  • i created it by using hibernate plugin and in the src/main/java Commented Aug 16, 2017 at 9:35
  • Can you show the actual error message? Commented Aug 16, 2017 at 9:36

3 Answers 3

1

thanks to all for giving your precious time . i got the solution by just makin changes as

Configuration con = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Alien.class);

Actually it was not getting the properties of hibernate.cfg.xml and class as well

Sign up to request clarification or add additional context in comments.

Comments

0

You shold add @Entity to Alien, as follows:

@Entity
public class Alien {

//...

}

1 Comment

That is OK. You can test my solution. If you have many class, adding @Entity to entity class is a better way.
0

Using password: YES, means, the password you have entered to connect to the database is not correct.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.