相关疑难解决方法(0)

如何在使用JPA和Hibernate时选择id生成策略

我正在浏览Hibernate参考指南的Id生成部分和"使用Hibernate的java持久性"

Hibernate和JPA结合使用有很多选项.

我正在寻找有关如何选择特定id生成策略的进一步文档.

我也在寻找引爆点.

例如,希望hilo策略可以减少争用.我假设必须有与此选择相关的权衡.

我希望接受有关权衡的教育.

有没有可用的文献?

java hibernate jpa uniqueidentifier id-generation

102
推荐指数
3
解决办法
15万
查看次数

hibernate无法获得下一个序列值

我有gwt应用程序连接到后端的postgres DB,以及一个java类'判断'映射数据库中的表'判断',当我试图将判断持久化到db时,它抛出了以下错误:

Caused by: org.hibernate.exception.SQLGrammarException: could not get next sequence value
...
Caused by: org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
Run Code Online (Sandbox Code Playgroud)

我的审判级看起来像这样

@Entity
@Table(name = "JUDGEMENTS")
public class Judgement implements Serializable, Cloneable {

    private static final long serialVersionUID = -7049957706738879274L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "JUD_ID")
    private Long _judId;
...
Run Code Online (Sandbox Code Playgroud)

我的表判断是:

   Column    |            Type             |                        Modifiers                        
-------------+-----------------------------+---------------------------------------------------------
 jud_id      | bigint                      | not null default nextval('judgements_id_seq'::regclass)
 rating      | character varying(255)      | 
 last_update | timestamp without time zone | 
 user_id     | …
Run Code Online (Sandbox Code Playgroud)

postgresql hibernate

44
推荐指数
4
解决办法
9万
查看次数

如何在 hibernate.cfg.xml 中连接 postgresql

我正在尝试通过休眠将一些数据插入到 postgresql 中。但是,关于使用postgresql配置hibernate的教程并不多(我知道,它应该类似于mysql =))

src/main/resources/hibernate.cfg.xml

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://127.0.0.1:5432/myDatabase</property>
<property name="connection.username">myUser</property>
<property name="connection.password">myPassword</property>

<!-- JDBC connection pool (use the build-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.HashtableCacheProvider</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<!-- thread is the short name for org.hibernate.context.ThreadLocalSessionContext -->
<property name="current_session_context_class">thread</property>

<!-- Set "true" to show SQL statements -->
<property name="hibernate.show_sql">true</property>

<!-- mapping class using annotation -->
<mapping class="com.hib.entities.Student"></mapping>
</session-factory>

</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

源代码/主/Java/

package com.hib.init;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class Hibernateutil …
Run Code Online (Sandbox Code Playgroud)

java database postgresql spring hibernate

6
推荐指数
1
解决办法
2万
查看次数