我正在使用带有 hibernate-core jar - 4.2.5.Final 的 maven 开发休眠应用程序。
这是实体:
public class Contact {
Long id;
String firstName;
String lastName;
String email;
//setters and getters
}
联系人.hbm.xml
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.sample.entity">
<class name="com.sample.entity.Contact" table="CONTACT">
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="firstName"><column name="FIRSTNAME" /></property>
<property name="lastName"><column name="LASTNAME"/></property>
<property name="email"><column name="EMAIL"/></property>
</class>
</hibernate-mapping>
RunContact.java
public class RunContact {
public static void main(String[] args) {
Session session = null;
try{
//sessionfactory
Configuration configuration = new Configuration().configure();
//SessionFactory factory = configuration.buildSessionFactory();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//session open
session = sessionFactory.openSession();
Contact contact = new Contact();
contact.setFirstName("Venu Kumar");
contact.setLastName("Indukuri");
contact.setEmail("venu@prokarma.com");
//save
session.save(contact);
}catch(Exception e){
e.printStackTrace();
}finally{
//session close
session.flush();
session.close();
}
}
}
当我运行这个应用程序时,我得到以下异常。
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
在解决问题方面的任何帮助表示赞赏。