How to set the timeout period on a JPA EntityManager query

Yes, there javax.persistence.query.timeout. According JPA 2.0 specification support for this query hint is optional: Portable applications should not rely on this hint. Depending on the persistence provider and database in use, the hint may or may not be observed. Default value (in milliseconds) can be set to persistence.xml for all queries: <property name=”javax.persistence.query.timeout” value=”1000″/> Same … Read more

Hibernate: How specify custom sequence generator class name using annotations?

please find below set of code which i have used in project for the same. @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “XyzIdGenerator”) @GenericGenerator(name = “XyzIdGenerator”, strategy = “com.mycompany.myapp.id.BigIntegerSequenceGenerator”, parameters = { @Parameter(name = “sequence”, value = “xyz_id_sequence”) }) public BigInteger getId() { return id; } package com.mycompany.myapp.id; import org.hibernate.id.SequenceGenerator; … public class BigIntegerSequenceGenerator extends SequenceGenerator … Read more

Java / Hibernate – Write operations are not allowed in read-only mode

That error message is typically seen when using the Spring OpenSessionInViewFilter and trying to do persistence operations outside of a Spring-managed transaction. The filter sets the session to FlushMode.NEVER/MANUAL (depending on the versions of Spring and Hibernate you’re using–they’re roughly equivalent). When the Spring transaction mechanism begins a transaction, it changes the flush mode to … Read more

How to call an Oracle function from Hibernate with a return parameter?

Hibernate Session provides a doWork() method that gives you direct access to java.sql.Connection. You can then create and use java.sql.CallableStatement to execute your function: session.doWork(new Work() { public void execute(Connection connection) throws SQLException { CallableStatement call = connection.prepareCall(“{ ? = call MYSCHEMA.MYFUNC(?,?) }”); call.registerOutParameter( 1, Types.INTEGER ); // or whatever it is call.setLong(2, id); call.setLong(3, … Read more

Can’t parse hibernate.cfg.xml while offline

Hibernate can resolve the DTDs locally (without a network connection). Your DOCTYPE is using the new namespace (http://www.hibernate.org/dtd/) for Hibernate 3.6, so you might have an older version of the Hibernate libraries in your classpath. I experienced the same issue after upgrading to Hibernate 3.6.8.Final. I had multiple versions of hibernate3.jar on the classpath causing … Read more

Grails 2.4 and hibernate4 errors with run-app

It’s a bug, it seems that you can leave it that way and will cause no problem, but if you don’t want to see the message here are some solutions: (Edit: Option 2 seems to work better (see comments in this post)) 1.- singleSession configuration from DataSource.groovy https://jira.grails.org/browse/GRAILS-11198 2.- overriding the H2 dialect: public class … Read more