Skip to content
Advertisement

Tag: jpa

Hibernate Check Annotation

I have a table with three fields, say a, b, c. I would like to add a constraint ensuring that if a is not null, then also b and c are not null. I have done that using following SQL Is there a way to achieve same effect using hibernate annotation @Check? I can’t find a helpful example with that

JPA @Column annotation to create comment/description

I was wondering is it possible to create from jpa/hibernate annotation a database column description/comment like this: ALTER TABLE tablename CHANGE status status INT(11) NOT NULL COMMENT ‘sample description/comment’; It will be great functionality, but I cant find anything about this in JPA specification. Maybe I should use @Column(columnDefinition=””) property, but I dont have any clue. Please help Answer I

Convert Hibernate @Formula to JOOQ field

I am rewriting entire DB access layer from Hibernate to JOOQ and I face following issue. One of JPA models is annotated with @Formula annotation as follows: Later in the code, a JPA query is made against the database which compares fee5 to parameter: How can above query be translated to JOOQ DSL? Answer I managed to resolve the issue

Using TIMESTAMPDIFF with JPA criteria query and hibernate as the provider

I have a data table with columns setup and release, both of which hold timestamps. My goal is to create an equivalent of the SQL query below using CriteriaQuery. SQL Query:SELECT TIMESTAMPDIFF(SECOND, setup, released)) as sum_duration FROM calls The CriteriaBuilder#diff() function clearly does not work as it requires parameters that are Numbers, so I tried using CriteriaBuilder#function: However, when I

Why does not Hibernate set @DynamicInsert by default

Could anyone explain to me why Hibernate does not set the @DynamicInsert annotation by default and allow entities to generate an INSERT based on the currently set properties? What’s the reason for not using @DynamicInsert and, therefore, including all entity properties by default? Answer What @jb-nizet said. Also, dynamic-insert=”true” is a bad idea in my book. Skipping null fields from

JPA with HIBERNATE insert very slow

I am trying to insert some data to SQL Server 2008 R2 by using JAP and HIBERNATE. Everything “works” except for that it’s very slow. To insert 20000 rows, it takes about 45 seconds, while a C# script takes about less than 1 second. Any veteran in this domain can offer some helps? I would appreciate it a lot. Update:

Substring in select statement in JPQL

I’m trying to select a substring of column, i.e. select substring(description, 1, 200) from category where id=1 Is it possible to have a substring function within a select statement in JPQL/JPA 2? If yes, how? If no, are there any alternatives? Thanks. Answer There is a scalar expression for this: SUBSTRING(string, start, end) I believe this is allowed in the

Advertisement