Java Hibernate postgres-关系“;“用户详细信息”;不存在
我刚从hibernate开始,我有一个简单的配置,当我第一次尝试保存我唯一的类时,它会给我这个错误:“relation”userdetails“notexist”Java Hibernate postgres-关系“;“用户详细信息”;不存在,java,hibernate,postgresql,Java,Hibernate,Postgresql,我刚从hibernate开始,我有一个简单的配置,当我第一次尝试保存我唯一的类时,它会给我这个错误:“relation”userdetails“notexist” 我的hibernate.gfg.xml文件: <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configura
我的hibernate.gfg.xml文件:
<!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>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">XXXX</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hdm2ddl.auto">create</property>
<mapping class="hibernate.project.UserDetails"/>
</session-factory>
</hibernate-configuration>
我的主要意见是:
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("First User");
Configuration config = new Configuration().configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session=sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
有什么想法吗?我发现了类似的问题,但没有帮助。谢谢 create属性不正确:使用hbm2ddl而不是hdm2ddl
<property name="hibernate.hbm2ddl.auto">create</property>
在你这方面似乎有输入错误。我认为这是一个类似这样的案例问题:我不知道我应该在代码中对你的示例做什么更改,我没有带名称的注释……我的意思是“Postgres(用于,不确定较新版本)将表名转换为小写。”@pL4Gu33:我明白了,我不知道该怎么办:(这似乎是mysql和postgres的基本配置之间的区别,以及工作和不工作之间的区别。mysql似乎不需要这样的条目。谢谢。
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hbm2ddl.auto">create</property>
hdm2ddl.auto