hibernate

How to debug Hibernate

Suppose I have a simple hibernate program. In this program having a hibernate query. How do I debug this query so that I can know which query elements have values and which do not. ...

What's the default hibernate session control behavior in spring?

I have a 3 layer application using spring and hibernate (controller -> service -> dao) and transaction is applied to service layer. I don't configure OpenSessionInViewInterceptor or OpenSessionInViewFilter and I want to know the hibernate session control behavior. Open session per transaction or per request? Thanks! ...

inserting values into multiple tables using hibernate

hello everyone, i have existing tables hotel and hotel_services. hotel table contains: hotel_id hotel_name hotel_services contains: hotel_id hotel_service_name each hotel can offer several services, so in my form user could enter as many services as he wants at a time. so for instance, hotel name: HOTEL1 hotel_services: 1. hotel_serv...

JPA/Hibernate support for migration?

Aloha, I'm currently working on a desktop application using JPA/Hibernate to persist data in a H2 database. I'm curious what my options are if I need to make changes to the database schema in the future for some reason. Maybe I'll have to introduce new entities, remove them or just change the types of properties in an entity. Is there...

Hibernate session.close() not returning connection to pool

My application has long running transactions and hence I tried the option session.close() at the end of every method to ensure that the connection objects are not held indefinitely for long time. When session.close() option is used, I could see that the Hibernate's session object and the corresponding Connection object obtained from se...

Different Hibernate validation annotations on same property

Greetings all i am using two validation annotations on a property in the bean @NotEmpty(message = "{name.required}") @Pattern(regex = "^([A-Za-z0-9]{2,}(\\-[a-zA-Z0-9])?)$", message = "{invalid.name}") private String name; if i left the name empty i got the two errors and i want only the first error message (if the first condition occ...

is there an "inverse" cascade in grails like there is in hibernate?

I have the following sql database that grails set up for me automatically. see picture for diagram http://yfrog.com/ngskillsdbj Whenever I try to delete all projects from an employee, I am getting a cascade re-save exception on the role_skill. Is that because of the way this is set up where role_skill is keyed into skill and role? I s...

Save child objects automatically using JPA Hibernate

I have a one-to-many relation between Parent and Child table. In the parent object I have a List<Child> setChilds(List<Child> childs) I also have a foreign key in the Child table. This foreign key is an ID that references a Parent row in database. So in my database configuration this foreign key can not be NULL. Also this foreign k...

Will Hibernate flush my updated persistent object when calling session.close()(using FlushMode.AUTO)?

Hi, It's pretty much in the title. I know that session.close() does not flush the session but what I'm not too sure is about the promise of FlushMode.AUTO. From the Docs: FlushMode.AUTO The Session is sometimes flushed before query execution in order to ensure that queries never return stale state. This is the default flush mode. ...

How can read-only collections be mapped in JPA / Hibernate that don't cause DB updates.

Hi all, is it possible to create relations in hibernate / jpa that are fetched when the containing entity is fetched but will never ever result in any db updates, when the containing entity is saved? I'll try to make the requirement clear by an example. I have a simple entity B @Entity public class B { private int bId; @Id ...

Force eager loading of otherwise lazy loaded properties

Hi. I've got a Hibernate object which's properties are all loaded lazy. Most of these properties are other Hibernate objects or PersistentSets. Now I want to force Hibernate to eager load these properties for just one time. Of course I could "touch" each of these properties with object.getSite().size() but maybe there's another way to...

JPA (Hibernate) - Session/Transaction and lazy loading

Hello! I have a Java EE project and the MySQL database is managed with an ORM. I worked a lot with Hibernate to learn what I am doing wrong and I think I understand session/transaction, but I do not know how I can solve this in my case/architecture. I have a Project and a Person which are in a bi-directional n:m relation with a join ta...

How to externalize properties from JPAs persistence.xml?

I would like to put some of the hibernate configuration in a property file to make it editable without build and deploy. I tried to solve my problem by following the instructions from http://stackoverflow.com/questions/1989672/create-entity-manager-without-persistence-xml app.properties: hibernate.show_sql=true hibernate.dialect=org...

getting result set into DTO in SQL Query in Hibernate

I have a query like below select f.id, s.name, ss.name from first f left join second s on f.id = s.id left join second ss on f.sId = ss.id If I could have used HQL, I would have used constructor syntax to directly populate DTO with the result set. But, since hibernate don't allow left join without having an association in place I have...

JPQL: How to include Forward Slash in Query String?

How do you properly escape a '/' forward slash in a JPQL query string? If I do this: LOCATE('/', REVERSE( ... I get: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query However, if I do this: LOCATE('\\', REVERSE( ... Everything is fine. So, how do I include the forward...

Memory Leak - com.mysql.jdbc.ConnectionPropertiesImpl$*ANY*ConnectionProperty

I seem to have a memory leak, one of the culprits seems to be the ConnectionProperty, whether it is String, Int or Boolean ones. e.g.:'com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty', millions seem to be staying around and not being GC'd. Here are my settings for the DB, Session Factory, Hibernate and Pooling etc..: ...

How can I change the name of the self-referential many-to-many set using hibernate.reveng.xml?

I have a project using Hibernate on an Oracle database for which all entities are generated directly from Hibernate Tools under control of a hibernate.reveng.xml file. I have one class which has a many-to-many relationship to itself using an intermediary table, like so: PERSON: ID ... PERSON_PERSON: PARENT_ID --> PERSON.ID CHI...

How do I select the nth element in a Collection by the number in an @IndexColumn?

I have an ItemEntity class, which has a collection of ImageEntity's. I want to be able to fetch a specific ImageEntity, given its index in the collection. For example, for an ItemEntity with 10 ImageEntity's, I want the 4th ImageEntity in as few database hits as possible. I've read Hibernate In Action and googled, but every piece of d...

How to change to case of a column to Upper in HQL Hibernate

Hi I want to change a column from a table to uppercase before using like and filtering what is the keyword in HQL? here's my query SELECT abc FROM ABC abc WHERE abc.id = ? And upper(abc.description) like '%?%' Thanks ...

Searching in a collection with JPA/Hibernate

Hi, I would like to make a query from an object I have defined that contains a collection. Object looks like this: @Entity public class ValidationLog { @Embeddable public static class ValidationLogPK implements Serializable { private String dataKey; @Enumerated(EnumType.STRING) private DataType dataType;...