Hibernate 3.6:架构导出失败,autocommit=false?
我正在阅读关于模式导出的hibernate书籍: 我试着在Hibernate 3.6中运行代码,但是没有创建模式,并且假设从输出日志来看,可能没有提交模式。以下是日志输出:Hibernate 3.6:架构导出失败,autocommit=false?,hibernate,Hibernate,我正在阅读关于模式导出的hibernate书籍: 我试着在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
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>
org.hibernate.dialogue.PostgreSqlDialogue
org.postgresql.Driver
索夫科
卡姆阿尔伯特
jdbc:postgresql://localhost:5432/hibernate
真的
org.hibernate.transaction.jdbc事务工厂
线
我想知道我在这里错过了什么
问候,
Albert Kam日志中似乎缺少一些内容,但可能是因为您没有用@entity标记实体 哇!我怎么会错过这个!哈哈。现在很好用了,谢谢你。尽管如此,在postgresql 9中创建表名user似乎有问题。将类名更改为MstUser后,它可以正常工作。以下是日志:drop table MstUser cascade。。删除序列休眠\u序列。。创建表MstUser(id int8非null,名称varchar(255),主键(id))。。创建序列休眠\u序列。。542[main]INFO org.hibernate.tool.hbm2ddl.SchemaExport-模式导出完成..“User”是PostgreSQL(可能还有Oracle)中的保留关键字。您不需要更改类名(也不应该更改)。只需引用@Entity(table=“
user
”)即可。我昨天也发现了这个注释。。谢谢!:)