HibernateException cannot be thrown

100 views Asked by At
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        Configuration cfg=new Configuration();
       
            try {
                cfg.configure("hibernate.cfg.xml");
            } catch (HibernateException e) {
                // TODO Auto-generated catch block
                  Throwable ex = (Throwable)e;
                    ex.printStackTrace();
            }
        
        SessionFactory factory=cfg.buildSessionFactory();
        
    }

It is giving me 2 errors first is No exception of type hiberbnateexception can be thrown,it should be a subclass of Throwable, Second is Cannot cast HibernateException to Throwable

My hibernate.cfg.xml is below:-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
    <session-factory>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/myhiber</property>
    <property name="connection.username">root</property>
    <property name="connection.password">rishabh123#</property>
    <property name="diaLect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hbm2dll.auto">update</property>
    <property name="show_sql">true</property>
    </session-factory>
    
    </hibernate-configuration>

and my pom.xml is :-


  <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>6.1.2.Final</version>
    <type>pom</type>
</dependency>

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.30</version>
</dependency>

  </dependencies>
</project>

These are the above dependencies that I have added

1

There are 1 answers

0
Rishabh Talwar On

the issue was resolved after adding

<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-core</artifactId>
    <version>4.7.0</version>
</dependency