hibernate

Keep DB connection using JPA/Hibernate

Hi there... I am using JPA and Hibernate in an application. (with PostgreSQL as DBMS) I execute a lot of select-statements to get items stored in the DB by their name. I use the following Code: //em is the javax.persistence.EntityManager Object. Query q = em.createQuery("Select i from Item i where i.name = :name"); q.set...

Collection property and Projections of Criteria API (Hibernate)

I have two entities that relate to each other as "many-to-one". So one type of the entity has a collection of child entities of another type. Is it possible to retrieve that collection property with Projections? I mean smth like criteria.setProjection( Projections.projectionList() .add( Projections.id() ) .add( Property.forName( "name"...

CriteriaQuery with JPA 1.0

Hello, Is it possible to use CriteriaQuery with JPA 1.0. I guess JPA 2.0 not available with Java Se ( version -- Java(TM) SE Runtime Environment (build 1.6.0_16-b01)) . I tied to use, CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Test> cq = cb.createQuery(Test.class); Root<Test> test= cq.from(Test.class); .... But cou...

Using Hibernate to fetch x number of object from a Set within a class/table

We are currently using Hibernate to fetch x number of objects out of the DB at a time for shoving into a ResultSet. Here is a sample code snippet: // create criteria Criteria criteria = GlobalState.createCriteria(HotlistRepository.class); criteria.createCriteria("owner").add(Restrictions.eq("displayName", user.getDisplayNam...

one-to-many entity referencing itself in hibernate

This seems to work, but is this the proper way for an entity to have a child set of the same entities? <hibernate-mapping> <class name="com.example.Person" table="Person"> <id name="id" column="Id" type="int"><generator class="native"/></id> <many-to-one name="childOf" class="com.example.Person" column="Child_of_Id"/...

NHibernate always does an update on the bag items of one-to-many

Hi, I was just wondering if it was normal for NHibernate to always update the item that are on the "many" side of a one-to-many mapping i.e. the items in the bag, even when there was no change. I have this: <class name="PrimaryClass" table="PrimaryTable" lazy="false"> <id name="Id" column="id"> <generator class="assigned" /...

Hibernate version?

I'm using JBoss Embedded version beta3.SP10 and I'm facing a persistence bug that is should be fixed in some Hibernate version. Sadly, I don't know what version of Hibernate is used in my JBoss Embedded and couldn't find a way to find this information, the hibernate-all.jar bundled in it doesn't contain a org.hibernate.Version class, n...

Lost with JPA @OneToMany and composite PK

I'm pretty lost with mapping the following structure with JPA annotations. +===========+ +====================+ | Offer | | Text | +-----------+ 1 0..* +--------------------+ | id (pk) |-------------| textkey (pk) | | namekey | | languagecode (pk) | | ... | ...

Autocreate Spring Entity "authorities" during testing

Hi all When trying unit tests with Spring Security & Hibernate, none of the security entities "user" or "authorities" are being autocreated. What I have done so far is to write an "user" bo that triggers generation of the appropiate table. However, I am stuck with the authorities: (as advised by http://java.dzone.com/articles/getting-s...

Derby database don't save entity after application running

I'm using Embedded Derby DB with hibernate. I'm saving some entities to database. After shutting down the application there is no entities in DB. Why it could be so? Below my Hibernate configuration <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "h...

Unable to get JPA working with Hibernate

For a weekend project I was trying to run JPA 2 with Hibernate 3.5. Please note that I am not getting any compile errors or runtime exceptions (when I deploy the war on Tomcat). Below is my code - persistence.xml <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x...

LEFT JOIN in Hibernate Query Language

Hi, I am trying to do a LEFT JOIN in Hibernate Query Language, in MySQL I can do this as follows: select * from day_timetable_timeslots t LEFT JOIN golfnine_date_time_entity d ON d.start_time = t.start_time In my table day_timetable_timeslots I have many time intervals for the whole day with 15 minute increments. eg. 00:00:00, 00:1...

How do you turn off Hibernate bean validation with JPA 1.0?

How do you turn off bean validation with Hibernate 3.x in a JPA 1.0 environment? I tried several things with persistence.xml: <persistence-unit name="bbstats" transaction-type="RESOURCE_LOCAL"> <properties> DB stuff <property name="javax.persistence.validation.mode" value="none" /> <property name="hibernate.validator.au...

Hibernate+JPA One To One relationship

I have a OneToOne relationship like this :- Person Others ----------- ------------- | id (PK) | <----------------->| id(PK)(FK) | ----------- ------------- | name | |.... | | address | |.... | | .... | ...

Unable to select a column from an Oracle View using JPA 2 Criteria API

I have an existing working query that selects a column from an entity mapped to an Oracle View using the following JPQL SELECT COUNT(o.id) FROM MyEntityView o I refactored it to use the JPA 2 Criteria API with the following code: MyEntityView model = new MyEntityView(); CriteriaBuilder criteriaBuilder = model.entityManage...

Hibernate: Retrieving Lists

Hi folks, I am a beginner with hibernate. My intetions are really simple: I have mapped objects into one table with annotations. Now I want to retrieve them as a List of objects to display them. Later I want to implement simple filters. Do I need to write SQL Queries? or is there a kind of Annotation based method? Option 1: see Rup...

ArrayIndexOutOfBoundsException in java and hibernate

i am using Hibernate and got the exception ArrayIndexOutOfBoundsException what are the possible causes? ...

Looking for spring-hibernate3-2.0.8 sources

I'm looking for the sources jar of spring-hibernate3-2.0.8 Jarvana only has the details to the jar with the compiled classes http://jarvana.com/jarvana/archive-details/org/springframework/spring-hibernate3/2.0.8/spring-hibernate3-2.0.8.jar Any idea where I could find it? I also tried mvn dependency:sources, but it couldn't find the so...

JPQL / HQL fetch join syntax for compatibility with EclipseLink & Hibernate

I would like to be able to swap my JPA implementation between EclipseLink & Hibernate with a simple property change. I can do this ok but what is causing me problems is the named query validation. Using EclipseLink I have to write fetch joins like so: SELECT id FROM IndexDefinition id JOIN FETCH id.index JOIN id.index i JOIN FETCH i....

Hibernate JPA one-to-one saving child class entity

I have a one-to-one relationship using PrimaryKeyJoinColumn annotated on the parent side. And now I want to save the child entity by itself. For example, I have Employee and EmpInfo as the child entity, I need to save EmpInfo (of course after setting the id property of the parent to it). However, when such an arrangement is used, I get ...