我正在阅读有关架构导出的hibernate书籍: http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=02validatingthehibernateenvironment
我尝试在Hibernate 3.6中运行代码,但是没有创建架构,并且从输出日志中假设,也许它不会以某种方式提交。这是日志输出:
105 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
118 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.0.Final
119 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
122 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
124 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
165 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
165 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
199 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
217 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
245 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.PostgreSQLDialect
291 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
295 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
295 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
297 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
297 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
297 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
306 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/hibernate
306 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sofco, password=****}
346 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
347 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:postgresql://localhost:5432/hibernate
这是我的代码:
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class User {
private Long id;
private String name;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* @param args
*/
public static void main(String[] args) {
Configuration config = new Configuration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);
}
}
这是我的hibernate cfg xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- MOHON DITAMBAHKAN SESUAI PACKAGE DAN URUT ABJAD -->
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.username">sofco</property>
<property name="connection.password">kamalbert</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/hibernate</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
我想知道我在这里失踪了什么..
此致
Albert Kam
答案 0 :(得分:1)
似乎日志中缺少一些东西,但可能是因为你没有用@Entity标记你的实体。