我想测试休眠工作在我的项目中,为此我试图创建会话,并且IDEA告诉我org.hibernate.HibernateException
和java.lang.Throwable
不兼容,并且我试图将其中一个施放到另一个也失败。项目是Java SE 8上的桌面应用程序,仅连接了hibernate-core-5.2.4.Final
和hibernate-commons-annotations-5.0.1.Final
库。 Main
类:HibernateException和Throwable
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Main {
public static void main(String[] args) throws Exception {
try {
SessionFactory session;
session = new Configuration().configure().buildSessionFactory();
session.openSession();
} catch (HibernateException e) { //fail
e = (Throwable)e; //fail
e.printStackTrace();
}
}
}
有hibernate.cfg
:
<hibernate-configuration>
<session-factory>
<property name=«show_sql»>true</property>
<property name=«connection.url»>jdbc:sqlite://db/DB.db</property>
<property name=«connection.driver_class»>org.sqlite.jdbc</property>
<property name=«connection.username»>root</property>
<property name=«connection.password»/>
<property name=«connection.pool_size»>1</property>
<property name=«current_session_context_class»>thread</property>
<property name=«dialect»>main.java.SQLiteDialect</property>
<!--> there're some mapping resouces
<mapping resource=«logic/File.hbm.xml»/>
<-->
</session-factory>
</hibernate-configuration>
我不明白,这个错误的原因,是因为谷歌搜索结果显示以下层次结构:
java.lang.Object
└extended by java.lang.Throwable
└extended by java.lang.Exception
└extended by java.lang.RuntimeException
└extended by org.hibernate.HibernateException
也许Java的8没有按” t支持正确的休眠,或者像这样smthng?
请发布堆栈跟踪的异常 –
我只是想知道为什么你会投掷'e =(Throwable)e;'。它总是给编译错误。 –
如果他们不兼容,铸造将不会改变... – Antoniossss