2016-03-20 5 views
0

я пытаюсь запустить приложение спящего режима, но исключение происходит .. Вот мой код ..any предложения .. спасибо заранееисключение запущенного приложения спящего режима

hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?> 
<hibernate-configuration> 

<session-factory> 

<!-- Related to the connection START --> 
<property name="connection.driver_class">com.mysql.jdbc.Driver </property> 
<property name="connection.url">jdbc:mysql://localhost:3306/mydb </property> 
<property name="connection.user">root </property> 
<property name="connection.password">root</property> 
<!-- Related to the connection END --> 

<!-- Related to hibernate properties START --> 
<property name="show_sql">true</property> 
<property name="dialet">org.hibernate.dialect.MYSQLDialect</property> 
<property name="hbm2ddl.auto">create</property> 
<!-- Related to hibernate properties END--> 

<!-- Related to mapping START--> 
<mapping resource="user.hbm.xml" /> 
<!-- Related to the mapping END --> 

</session-factory> 
</hibernate-configuration> 

user.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<hibernate-mapping> 

<class name="DataProvider" table="user_info"> 

<id name="user_id" column="id"> 
<genereator class="assigned" /> 
</id> 

<property name="vuser_name" column="name"/> 
<property name="user_address" column="address"/> 
</class> 

</hibernate-mapping> 

DataProvider.java:

public class DataProvider { 
    private int user_id; 
    private String user_name; 
    private String user_address; 
    public int getUser_id() { 
     return user_id; 
    } 
    public void setUser_id(int user_id) { 
     this.user_id = user_id; 
    } 
    public String getUser_name() { 
     return user_name; 
    } 
    public void setUser_name(String user_name) { 
     this.user_name = user_name; 
    } 
    public String getUser_address() { 
     return user_address; 
    } 
    public void setUser_address(String user_address) { 
     this.user_address = user_address; 
    } 


} 

DataInsertion.java:

public class DataInsertion { 

    public static void main(String[] args) { 
     new DataInsertion().insertInfo(); 

    } 

    public void insertInfo(){ 
     Configuration con = new Configuration(); 
     con.configure("hibernate.cfg.xml"); 
     SessionFactory sf = con.buildSessionFactory(); 
     Session session = sf.openSession(); 

     DataProvider provider = new DataProvider(); 
     provider.setUser_id(121); 
     provider.setUser_name("name"); 
     provider.setUser_address("adress"); 

     Transaction tr = (Transaction) session.beginTransaction(); 
     session.save(provider); 
     System.out.println("Object Saved"); 
     try { 
      tr.commit(); 
     } catch (SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException 
       | SystemException e) { 
      e.printStackTrace(); 
     } 
     session.close(); 
     sf.close(); 


    } 

} 

и исключение составляет

20 марта 2016 12:49:01 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager ИНФОРМАЦИЯ: HCANN000001 : Hibernate Commons Annotations {5.0.1.Final} 20 марта 2016 12:49:01 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity WARN: HHH90000012: признано устаревшее пространство имен спящего режима http://hibernate.sourceforge.net/hibernate-mapping , Вместо этого используйте пространство имен http://www.hibernate.org/dtd/hibernate-mapping. Поддержка устаревших пространств имен DTD/XSD может быть удалена в любое время. Исключение из потока «main» org.hibernate.boot.InvalidMappingException: не удалось проанализировать документ сопоставления: user.hbm.xml (RESOURCE) на org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind (InputStreamXmlSource.java:46) на org.hibernate.boot.jaxb.internal.UrlXmlSource.doBind (UrlXmlSource.java:36) на org.hibernate.boot.spi.XmlMappingBinderAccess.bind (XmlMappingBinderAccess.java:59) на org.hibernate.boot .MetadataSources.addResource (MetadataSources.java:274) at org.hibernate.boot.cfgxml.spi.MappingReference.apply (MappingReference.java:70) at org.hibernate.boot.internal.MetadataBuilderImpl.build (MetadataBuilderImpl.java : 413) at org.hibernate.boot.internal.MetadataBuilderImpl.build (MetadataBuilderImpl.java:87) в org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java:692) в org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java:724) в DataInsertion.insertInfo (DataInsertion.java:22) на DataInsertion.main (DataInsertion.java:15) Вызвано: org.hibernate.boot.MappingException: невозможно выполнить размаркировку в строке с номером 9 и столбцом 32. Сообщение: cvc-complex-type.2.4.a: обнаружен недопустимый контент начиная с элемента «genereator». Один из {{http://www.hibernate.org/xsd/orm/hbm ": meta," http://www.hibernate.org/xsd/orm/hbm ": столбец," http://www.hibernate.org/xsd/orm/hbm ": type," http://www.hibernate.org/xsd/orm/hbm ": generator} '. : origin (user.hbm.xml) at org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb (AbstractBinder.java:177) at org.hibernate.boot.jaxb.internal.MappingBinder.doBind (MappingBinder.java : 61) at org.hibernate.boot.jaxb.internal.AbstractBinder.doBind (AbstractBinder.java:102) at org.hibernate.boot.jaxb.internal.AbstractBinder.bind (AbstractBinder.java:57) at org .hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind (InputStreamXmlSource.java:43) ... 10 более Вызванный: javax.xml.bind.UnmarshalException - со связанным исключением: [org.xml.sax. SAXParseException; lineNumber: 9; columnNumber: 32; cvc-complex-type.2.4.a: Недействительный контент был найден, начиная с элемента genereator.Один из {{http://www.hibernate.org/xsd/orm/hbm ": meta," http://www.hibernate.org/xsd/orm/hbm ": столбец," http://www.hibernate.org/xsd/orm/hbm ": type," http://www.hibernate.org/xsd/orm/hbm ": generator} 'ожидается.] at com.sun.xml.internal.bind.v2.runtime.unmarshaller .UnmarshallerImpl.handleStreamException (Неизвестный источник) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0 (Неизвестный источник) at com.sun.xml.internal.bind.v2.runtime.unmarshaller .UnmarshallerImpl.unmarshal (Unknown Source) в org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb (AbstractBinder.java:171) ... 14 более

+0

В ваших конфигурационных файлах имеется множество орфографических ошибок, например. г. 'genereator' вместо' generator', 'dialet' вместо' dialect' и, возможно, больше. Поэтому неудивительно, что он не может бежать. –

ответ

1

Там опечатка в вашем user.hbm .xml. Вместо «генератора» вы написали «genereator». Исправьте его, и он должен работать.

+0

появляется ошибка в этой строке: «Транзакция tr = (транзакция) session.beginTransaction();» –

+0

Опубликуйте stacktrace, пожалуйста. – Aurasphere

Смежные вопросы