gpt4 book ai didi

java - 配置hibernate 5.0.2时出错

转载 作者:行者123 更新时间:2023-12-01 11:05:51 24 4
gpt4 key购买 nike

我在使用 hibernate 5.0.2 时遇到问题,我尝试找到解决方案但失败了。不知道问题出在哪里。

这是 hibernate.cfg.xml

<?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.username">mecro</property>
<property name="connection.password">mecro1234</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver/property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName="Micarle";characterEncoding=UTF-8</property>
<property name="dialect">org.hibernate.dialect.SQLServer2012Dialect.class</property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>

<mapping resource="Students.hbm.xml"/>
</session-factory>

这是测试类

public class StudentsTest {
private SessionFactory sessionFactory;
private Session session;
private Transaction transaction;

@Before
public void init(){
//Configuration config = new Configuration().configure();

StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();

session = sessionFactory.openSession();

transaction = session.beginTransaction();
}
@After
public void destroy(){
transaction.commit();
session.close();
sessionFactory.close();
}

@Test
public void testSaeStudents() {
Students s = new Students(1, "mecro", "man", new Date(), "montains");
session.save(s);
}

这是我将类作为 junit 测试运行时的错误

 org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number -1 and column -1 in RESOURCE hibernate.cfg.xml. Message: unexpected element (uri:"http://www.hibernate.org/xsd/orm/cfg", local:"property"). Expected elements are <{

此错误后面有一些失败跟踪。但我无法复制它,我认为它们没有任何意义

最佳答案

查看您指定 SQLServerDriver 属性的行...您错过了 <

关于java - 配置hibernate 5.0.2时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32962143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com