Hibernate配置错误(找不到元素’hibernate-configuration’的声明)
我正在尝试使用hibernate建立与数据库的简单连接。 这是我的配置文件:
org.hsqldb.jdbcDriver jdbc:hsqldb:hsql://localhost user pass 1 org.hibernate.dialect.HSQLDialect thread org.hibernate.cache.internal.NoCacheProvider true update
我收到以下错误:
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 6 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'. ...
似乎有点不合逻辑。 因为我将’hibernate-configuration’作为hibernate.cfg.xml文件中的根元素。
我正在使用Hibernate 4.1.1(刚才提到,因为我已经得到一些提示,新的hibernate可能会有一些问题)
希望有人可以提供帮助,因为我是Hibernate的新手,现在我也没有得到谷歌的任何重大帮助。
使用以下命令构建会话工厂 –
new Configuration().configure().buildSessionFactory();
至于Hibernate.cfg,你可以试试下面的标题。
目前Hibernate 4.1似乎遇到了错误(不确定稳定性)。 我在邮件列表中找到了解决方案,所以也要检查一下。 希望这可以帮助。
http://www.mail-archive.com/hibernate-dev@lists.jboss.org/msg06937.html
创建会话工厂作为新的AnnotationConfiguration()。 配置 ()。 buildSessionFactory(); 希望它能帮助你建立联系……
试试这个代码。
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction();
将标头添加到您的XML文件中
--------