postgresql-Hibernate程序中的错误
我刚开始使用Hibernate,但第一个程序本身就出现了错误。请帮我识别错误。这是代码。我正在使用Hibernate 4.2.7和postgreSQL 9.3 hibernate.cfg.xml hibernatest.java 我面临的错误是postgresql-Hibernate程序中的错误,hibernate,postgresql,Hibernate,Postgresql,我刚开始使用Hibernate,但第一个程序本身就出现了错误。请帮我识别错误。这是代码。我正在使用Hibernate 4.2.7和postgreSQL 9.3 hibernate.cfg.xml hibernatest.java 我面临的错误是 org.hibernate.MappingException:配置无效 位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2095) 位于org.hibernate.cfg.
org.hibernate.MappingException:配置无效
位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2095)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:2012)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:1991)
位于org.hibernate.test.HibernateTest.main(HibernateTest.java:19)
原因:org.xml.sax.saxpasseeption;行号:3;栏目号:25;文档无效:未找到语法。
更新:
在做了一些修改后,它工作了。我将xml内容更改为此
hibernate.cfg.xml
org.postgresql.Driver
jdbc:postgresql://localhost:5432/hibernatedb
博士后
密码
1.
org.hibernate.dialogue.PostgreSqlDialogue
线
org.hibernate.cache.internal.NoCacheProvider
真的
创造
将配置文件中的头文件更改为 hibernate.cfg.xml
您是否尝试删除了hibernate-configuration-4.0.xsd中所有多余的空格
这只是在此处复制时出现的一个打字错误。谢谢你的检查。现在问题解决了,删除你的问题,或者自己回答。
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate- configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="org.hibernate.tutorial.dto.UserDetails"/>
package org.hibernate.tutorial.dto;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetails {
@Id
private int userId;
private String userName;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
package org.hibernate.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tutorial.dto.UserDetails;
public class HibernateTest {
/**
* @param args
*/
public static void main(String[] args) {
UserDetails mUser = new UserDetails();
mUser.setUserId(1);
mUser.setUserName("freak");
try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(mUser);
session.getTransaction().commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<?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">
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="org.hibernate.tutorial.dto.UserDetails"/>
<?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">