我正在使用Postgres 9.2,hibernate 4.3.0 final。運行一個簡單的Hibernate項目沒有效果
我有testClass
:
@Entity
@Table(name="testClass")
public class testClass implements Serializable {
@Id
@Column(name = "id")
private Integer id;
@Column(name="name")
private String name;
public Integer getId() {
return id;
}
}
從另一個類的方法創建:
try {
new Configuration().configure("/hibernate.cfg.xml");
new testClass();
} catch(Exception e) {
System.out.println(e);
}
這裏是我的hibernate.xml.cfg:
<?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 name="postgres">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="testClass"/>
</session-factory>
</hibernate-configuration>
它執行的JBoss服務器端:
[2014-01-06 05:59:01,592] Artifact server:ejb: Artifact is deployed successfully
17:59:22,880 INFO [org.hibernate.cfg.Configuration] configuring from resource: /hibernate.cfg.xml
17:59:22,881 INFO [org.hibernate.cfg.Configuration] Configuration resource: /hibernate.cfg.xml
17:59:22,889 INFO [org.hibernate.cfg.Configuration] Configured SessionFactory: postgres
但沒有任何反應:(
我正在檢查我的PostgresDB中的新表,但沒有任何東西。
我錯過了什麼?
我認爲你什麼都不做;只是打開它並閱讀它 –
感謝您提供所有正確的細節,從一開始就有一個很好的問題。如果可以的話,我會+10。 –