hibernate

oracle SUBSTR date duration

when i do query SUBSTR(e.updatetime - s.updatetime, 1,30) i will get result below +000000001 05:06:47.388000 can this save in java.util.Date? or which java class should i use other than String to ease me retrieve day,minutes,hours... p/s: e.updatetime is timestamp type ...

What other libraries or tools would you add to a Spring/Hibernate stack for improved rapid application development?

My team at work maintains a fairly large webapp written on top of Spring and Hibernate. We're about to start making some fairly large scale changes to the site, and we're enamored with the rapid application development speeds allowed by some other frameworks, like Rails. We haven't really changed our stack much in the last year or two,...

sql optimize search many-many

usertable ---- id, username grouptable ---- id, groupname group_user -------- uid, gid books ---- id, groupname Input parameters: groupname, username output: list of books Is it possible to use 1 sql statement to get list of books when username is inside groupname Question 2: any good book to recommand to master complex sql st...

hibernate show_sql value

this is example of how sql is showed when using show_sql=true Hibernate: select propertyse0_.entity_name as entity1_3_0_, propertyse0_.entity_id as entity2_3_0_, propertyse0_.entity_key as entity3_3_0_, propertyse0_.key_type as key4_3_0_, propertyse0_.boolean_val as boolean5_3_0_, prop...

Dynamic order by in JPA/Hibernate?

The naive attempt query would look like this: Query query = em.createQuery("from org.domain.Resource r where r._parent = ? order by ?"); This does not work as the parameters should be data and not column names or syntax like ASC or DESC. What kind of workarounds you have figured out for this dynamic ordering? Concatenating the orderi...

Java-Spring-Hibernate: How can I save a filter and, afterward, how could I use it?

I receive a task for a project which uses Spring, Hibernate and Wicket. In a particular HTML page I must have the possibility to create a filter(set the name of the filter and its parameters). I must create a list of filters in this way. In the same time, I must have the possibility to edit and delete the filter, and of course, to use t...

JPA Hibernate: How to prevent join on retrieving?

Suppose I have the following objects (one table per object) with this relations: A -> B -> C -> D If I findById an instance of A, all B, C and D are returned which is not I want. Is this possible to force Hibernate only to return A (or only it's primitive properties)? I know that I can write "SELECT a.x, a.y, a.z, ... FROM A" and then ...

Java/eclipse/hibernate

Hi I'm a .net dev, usually do this using nhibernate and can work with that fine. I'm doing a project which needs to be written in Java and have the following issue: All I have so far is a blank java project setup in eclipse. I have C:\work\lib\java\cp\hibernate3.jar in the Referenced Libraries node in the package explorer. in my code ...

Convert hibernate HQL with collection.size to criteria query

For some reason I can never figure out how to do things via criteria api. I have a HQL: from Track track where size(track.trackTitles) > 1 Is it possible to convert it into a criteria query on Track class? If yes, how: what Restriction should I use? ...

Spring + Hibernate + JPA

As of now I have a working Spring application with persistence. However now I want to use Hibernate with JPA to do all of my database activities. I want to do this using an entitymanager. I've been reading many documents and tutorials on this matter, I've been getting confused on whether I need a persistence.xml file or not. Also I've ...

setting up associations directly through ids in grails

I have 2 domain objects with a one-to-many relationship. Just as an example: Class Author{ static hasMany = [posts: Post] } Class Post{ Author author } In the database the post table has a field called author_id. In my application, I have a bunch of author ids that I want to associate with posts. I can do this by first querying th...

Another Spring + Hibernate + JPA question

I'm still struggling with changing my Spring Application to use Hibernate with JPA to do database activities. Well apparently from a previous post I need an persistence.xml file. However do I need to make changes to my current DAO class? public class JdbcProductDao extends Dao implements ProductDao { /** Logger for this class and s...

Hibernate search API with 2 tables

Hello I am trying to make a query with Hibernate criteria API. It looks simple but I can't get it to work. I have 2 tables. Person and Roles. Person has a set of roles. Role doesn't have any reference to Person. (i.e a guy A can be admin, user, another girl B can be only admin, etc...) I just want to to search for everyone who is doing ...

Hibernate - clearing a collection with all-delete-orphan and then adding to it causes ConstraintViolationException

I have these entities class Foo{ Set<Bar> bars; } class Bar{ Foo parent; String localIdentifier; } With this mapping (sorry, no annotations, I'm old fasioned): <class name="Foo"> ... <set name="bars" cascade="all-delete-orphan" lazy="false" inverse="true"> <key>...</key> <one-to-many class="Bar"/>...

Using DTO Pattern to synchronize two schemas ?

I need to synchronize two databases. Those databases stores same semantic objects but physically different across two databases. I plan to use a DTO Pattern to uniformize object representation : DB ----> DTO ----> MAPPING (Getters / Setters) ----> DTO ----> DB I think it's a better idea than physically synchronize using SQL Query on e...

Junit tests fails randomized while using database and entity manager

I try to write an big test class. I'm using Junit, Hibernate and TopLink and H2 database. Before this I used EJB3Unit (including Hibernate and H2). My test class has 57 test methods. If I run all test at once randomized one or more test fails. If I run each test alone, I get no error. Has anyone an idea what's going wrong? And how I c...

Hibernate and Unexpected end of Subtree exception

Hi, all I'm a newbie to Hibernate, so please bear with me if this is obvious or something. I have an Item POJO which contains a Set<String> consisting of labels. The labels are contained on another Database table from the Item table, so I do a join to populate the pojo. I'm trying to run a simple example query from the book "Java Pers...

Elegant way to handle upsert with Hibernate and MySQL

I'm currently working on a batch import feature that sits on top of Hibernate and MySQL. My goal is to have Upsert functionality for several tables. I'm finding myself writing a lot of code to deal with seeing if the row exists by key and branching to right method. I was wondering if there might be a better way, i.e. something analogous ...

Efficient representation of Hierarchies in Hibernate.

I'm having some trouble representing an object hierarchy in Hibernate. I've searched around, and haven't managed to find any examples doing this or similar - you have my apologies if this is a common question. I have two types which I'd like to persist using Hibernate: Groups and Items. * Groups are identified uniquely by a combination...

Group by month with criteria in Hibernate

Hi Guys, I'm trying to get a report using Criteria and ProjectionList, and I'm pretty new using this through hibernate. So I have this model: private Long _userId; private Category _category; private Long _companyId; private Double _amount; private Date _date; And I building the query using this: public List sumPaymentsByU...