I’m using hibernate 4.2.6 and PostgreSQL 9.1 I’ve been trying to execute sql query with hibernate. I’ve written: Session session = Hibernate.util.HibernateUtil.getSessionFactory().openSession(); …
Tag: hibernate
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:
Inserting NULL into MySQL timestamp
I’m observing unexpected behavior with inserting/updating NULL in a MySQL timestamp column. Consider the following statements. The first insert (when hiredate is not specified in the SQL, hireDate is null(0) which is expected. However when an explicit null passed in SQL, the current date time is inserted which is unexpected. Why does this happen? Note: Hibernate uses second type of
Oracle Sequence Transactionality
I need for a particular business scenario to set a field on an entity (not the PK) a number from a sequence (the sequence has to be a number between min and max I defined the sequence like this : …
NonUniqueDiscoveredSqlAliasException when two table has same column names
I have two tables Item and Nikasa – whose definitions looks like: Item { id, name, spec} and Nikasa {id, date, item_id}. Here item_id represents Item.id. I did a simple native SQL join to select only Item.id and Nikasa.id as: But I am getting exception NonUniqueDiscoveredSqlAliasException : Encountered a duplicated sql alias [ID] during auto-discovery of a native-sql query at
Insert with Hibernate native query does not work for java.util.Date
I am using Hibernate JPA and Spring with a Mysql database and I want to insert using a SQL statement like this: But after running it I get the following error: Could someone help me on this please? PS. I am aware of using hibernate in non-native way, but I need to use native way. I am also of insert