hibernate

Hibernate thread-safe collections

人走茶凉 提交于 2021-02-07 08:57:37
问题 This is somewhat of a continuation of Hibernate session thread safety. All of the details apply here as well. In simplified terms, execution follows the pattern of: 1. Read entity 2. Do expensive, easily parallelizable work 3. Persist changes The entities are all configured for eager loading, and the session is not accessed at all during 2. The work involved in 2 requires infrequent modification of a persistent collection. This is what I have now: synchronized (parentEntity) { parentEntity

Hibernate thread-safe collections

那年仲夏 提交于 2021-02-07 08:56:53
问题 This is somewhat of a continuation of Hibernate session thread safety. All of the details apply here as well. In simplified terms, execution follows the pattern of: 1. Read entity 2. Do expensive, easily parallelizable work 3. Persist changes The entities are all configured for eager loading, and the session is not accessed at all during 2. The work involved in 2 requires infrequent modification of a persistent collection. This is what I have now: synchronized (parentEntity) { parentEntity

Dropwizard @UnitOfWork with asynchronous database call

混江龙づ霸主 提交于 2021-02-07 08:56:06
问题 I imagine that this is a common problem, but after some searching I wasn't able to find anything relevant. The problem I'm having is that I'm getting a No Hibernate Session bound to thread exception when annotating my resource method with @UnitOfWork and inside my resource method, making an asynchronous DAO call. The idea behind this design is to make the database call on a separate I/O thread so that it frees up the Jersey resource thread. Unfortunately, as the exception says, this

Can I reuse a column across subclasses in a Hibernate table-per-hierarchy inheritance strategy?

此生再无相见时 提交于 2021-02-07 08:37:54
问题 In a simple inheritance tree, an abstract superclass has two subclasses. The subclasses both store a key-value pair, but but one will be holding a type Encrypted String, and the other one a plain old String. Now, my question is can I do this: @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract Attribute { @Id private Integer id; @Column(name="attribute_key") private String key; } @Entity public EncryptedAttribute extends Attribute { @Column(name="attribute_value")

Can I reuse a column across subclasses in a Hibernate table-per-hierarchy inheritance strategy?

纵饮孤独 提交于 2021-02-07 08:36:35
问题 In a simple inheritance tree, an abstract superclass has two subclasses. The subclasses both store a key-value pair, but but one will be holding a type Encrypted String, and the other one a plain old String. Now, my question is can I do this: @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract Attribute { @Id private Integer id; @Column(name="attribute_key") private String key; } @Entity public EncryptedAttribute extends Attribute { @Column(name="attribute_value")

How to configure hibernate in standalone (Swing) application in eclipse?

允我心安 提交于 2021-02-07 07:36:34
问题 i usually use hibernate with spring in web applications so i use DI and maven for configuration, now i want to use hibernate in desktop/swing application that doesn't use maven or spring, and i was wondering about the following: What jars do i need ? How to configure the hibernate, and how to make a sample query ? please advise, thanks. 回答1: I don't know about Spring, so you will have to update my answer a little if you really want to use it (for instance Spring has its own mechanism for

Hibernate with Kotlin: @ManyToOne(fetch = FetchType.LAZY)

不打扰是莪最后的温柔 提交于 2021-02-07 07:32:12
问题 I am using Hibernate with Kotlin and I am having an issue with FetchType.LAZY on @ManyToOne relations. Consider following: @ManyToOne(fetch = FetchType.LAZY) open var event: Event? The problem is that when FetchType.LAZY is used, the fetched Event will be of class Event_$$_jvst_... with JavaassistLazyInitializer on it. But the event will never be initialized, everything will be null or empty. Once the FetchType.LAZY is removed, everything works correctly. This didn't happen in Java. I tried

Does committing transaction close session?

∥☆過路亽.° 提交于 2021-02-07 07:25:11
问题 I am new to hibernate. Does session.getTransaction().commit() , close the session? Because in the api documentation it is not mentioned that it closes the session. In my code I have session.getTransaction().commit(); session.close(); But I get following exception org.hibernate.SessionException: Session was already closed If I remove session.close() , then I do not get this exception. 回答1: You can find more info about it here. Basically, this depends on how you obtained the session and what is

How to configure package level @TypeDefs with Spring Hibernate

谁说胖子不能爱 提交于 2021-02-07 06:52:30
问题 I need to configure @TypeDefs for use custom @Type on package level. When I configured it following manner I am getting ClassNotFoundException. But when I put @TypeDefs on the class level it is working fine. I have found similar kind of stackoverflow post but I haven't any idea to how to configure <resource package="com.foo.bar.thepackage"/> entry with my application-context.xml file. According some post (as bellow), noted this a Spring related bug I believe this is due to a bug in Spring,

@Transactional(readOnly = true) leads to LazyInitializationException

狂风中的少年 提交于 2021-02-07 06:29:05
问题 I have a many-to-many relation with an additional column in the link table. I've configured it in a way that the owning side fetches children eager (so I don't get LazyInitializationException ) and in the opposite direction it is lazy. This works. I now wanted to fine-tune the transactions (before there was just @Transactional on class level of DAO and Service classes. I set method getById to readOnly = true : @Transactional(readOnly = true) public Compound getById(Long id) { return