簡體   English   中英

配置休眠5.0.2時出錯

[英]Error in configuring hibernate 5.0.2

使用休眠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屬性的行..您錯過了<

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM