2016-02-26 87 views
0

我有这样 enter image description here错误运行Hibernate项目15.0.3

Hibernate项目结构我的hibernate.cfg.xml是

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
     "-//Hibernate/Hibernate Configuration DTD//EN" 
     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=WSMS</property> 
     <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 
     <mapping class="test.IssuesEntity"/> 
     <!-- DB schema will be updated if needed --> 
     <!-- <property name="hbm2ddl.auto">update</property> --> 
    </session-factory> 
</hibernate-configuration> 

我的主类是

public class Main { 


    public static void main(String[] args) throws Exception { 
    /// System.out.print("jajaja"); 
     Configuration cfg=new Configuration(); 
     cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file 

     //creating seession factory object 
     SessionFactory factory=cfg.buildSessionFactory(); 

     //creating session object 
     Session session=factory.openSession(); 

     //creating transaction object 
     Transaction t=session.beginTransaction(); 

     IssuesEntity e1=new IssuesEntity(); 
     // e1.setId(115); 
     // e1.setFirstName("sonoo"); 
     // e1.setLastName("jaiswal"); 
     e1.setIssueName("akash"); 

     session.persist(e1);//persisting the object 

     t.commit();//transaction is commited 
     session.close(); 

     System.out.println("successfully saved"); 
    } 
} 

但是,每当我运行项目它显示以下错误

Feb 26, 2016 10:02:59 PM org.hibernate.annotations.common.Version <clinit> 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} 
Feb 26, 2016 10:03:00 PM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.2.2.Final} 
Feb 26, 2016 10:03:00 PM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
Feb 26, 2016 10:03:00 PM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 

我遵循intellij指令,但我找不到任何解决方案。请帮忙

回答

1

这不是一个错误。这只是一个信息,您在类路径中没有hibernate.properties文件。你在hibernate.cfg.xml有属性,也没关系。但是您需要指定hibernate.dialecthibernate.connection.usernamehibernate.connection.password

如果你没有在数据库表中你需要这个太

<property name="hbm2ddl.auto">update</property> 
+0

我已经在hibernate.cfg.xml加入这个环节的帮助下http://www.tutorialspoint.com /hibernate/hibernate_configuration.htm,它的工作原理。谢谢你的解释 –

+0

@syedmhamudulhasanakash欢迎你:) –