[英]Chats aren't being added to the ArrayList even though I can see that they are being saved to Firebase
[英]Even though Hibernate is added it is not being imported
这是Hibernate的SessionUtil,出现错误:
import org.hibernate.Session; //Error in here
import org.hibernate.SessionFactory; //Error in here
import org.hibernate.cfg.Configuration;//Error in here
public class SessionUtil {
private static SessionUtil instance=new SessionUtil();
private SessionFactory sessionFactory;
public static SessionUtil getInstance(){
return instance;
}
private SessionUtil(){
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
sessionFactory = configuration.buildSessionFactory();
}
public static Session getSession(){
Session session = getInstance().sessionFactory.openSession();
return session;
}
}
我已经在代码的第1 3行中进行了注释,以向您显示我在哪里出错。 实际上,我几乎在任何与休眠相关的命令(例如SessionFactory,Transaction,Commit等)上都会出错。
但是我添加了Hibernate和mysql Connector的dependecy。
我在pom.xml中添加的依赖项在这里:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
在资源中,我还添加了hibernate.cfg.xml ::
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="hibernateSessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testdb</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- <property name="hibernate.hbm2ddl.auto">create</property> -->
<mapping class="com.example.model.User"/>
</session-factory>
</hibernate-configuration>
有人可以在我错的地方帮助我。 谢谢。
我无法从您的pom.xml片段中分辨出来,但是也许您将这些依赖项放在了<dependencyManagement>
部分而不是<dependencies>
部分中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.