hibernate

Getting all objects with a certain element inside a collection of strings with criteria API.

Hey. I'm trying to build a Hibernate Criteria query to find entities that have a specific element inside a collection. We can take as an example a Book -object that looks like this: public class Book { private Long id; private String title; private Set<String> authors = new HashSet<String>(); } The entity is mapped like this: ...

Mapping tables from an existing database to an object -- is Hibernate suited?

Hello! I've got some tables in an existing database and I want to map them to a Java object. Actually it's one table that contains the main information an some other tables that reference to such a table entry with a foreign key. I don't want to store objects in the database, I only want to read from it. The program should not be allow...

Hibernate annotated many-to-one not adding child to parent Collection

I have the following annotated Hibernate entity classes: @Entity public class Cat { @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id private Long id; @OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch = FetchType.EAGER) private Set<Kitten> kittens = new HashSet<Kitten>(); public v...

Spring, Hibernate and Ehcache - Wrong entities

Hi there, I've got a webapp which uses spring+hibernate for my data layer. I'm using 2nd level caching with ehcache as provider. Everything seems to work so far but sometimes we encounter a problem which I can't really figure out atm. One of my tables is used for labels within the application - every user who logs access this table wit...

newbie hibernate first level cache confusion

Hi all I'm just geting to grips with hibernate. Little bit confused. I just wanted to watch the operation of the first level cache, which I understood to batch up queries until the end of the session. But if I create an object, hibernate saves it immediately, so that when I later update it in the same transaction, it has to do an updat...

Deleting from ManyToMany with IndexColumn

Report.entity { @ManyToMany @JoinTable(name = "reports_contents_relations", joinColumns = @JoinColumn(name = "report_id"), inverseJoinColumns = @JoinColumn(name = "content_id")) @IndexColumn(name="content_order") private List contents = new ArrayList(); } Someclass { public void remoteContentFromReport...

hibernate p6spy problem

Hi all I'm trying to get to grips with what hibernate is doing under the hood, and I'm using p6spy as a proxy for the mysql jdbc driver so I can see what's really going to the database. I'm a little confused by the output from p6spy however - grateful for any light! The problem is this. I'm creating two new objects of class Test1, name...

Hibernate ManyToMany and superclass mapping problem

Hi all, I need to create a relation in Hibernate, linking three tables: Survey, User and Group. The Survey can be visible to a User or to a Group, and a Group is form of several Users. My idea was to create a superclass for User and Group, and create a ManyToMany relationship between that superclass and Survey. My problem is that Grou...

What is a good solution to link different tables in Hibernate based on some field value?

I have article table and several user tables a_user, b_user, ... with exactly the same structure (but different data). I can't change anything in *_user tables except their table name prefix but can change everything else (user tables contain only user information, there is nothing about article or user_type in them). I need to link art...

Testing Hibernate DAO, without building the universe around it.

We have an application built using spring/Hibernate/MySQL, now we want to test the DAO layer, but here are a few shortcomings we face. Consider the use case of multiple objects connected to one another, eg: Book has Pages. The Page object cannot exist without the Book as book_id is mandatory FK in Page. For testing a Page I have to cr...

HQL to JPQL question

What is the translation of the following HQL query to EclipseLink compliant JPQL : select p from NameList list, Person p where p.name in elements(list.names) (this is just a variation of a HQL example query taken from here) In EclipseLink the IN function doesn't seem to take property paths : Internal Exception: NoViableAltException(...

hibernate second level ehcache miss problem

Hi all I'm trying to get a second-level hibernate cache working, using the ehcache implementation. I'm sure it's some obvious noob mistake I'm making, but I can't see what it is! To test out my cache, I'm doing the following: Creating an object and saving it. I 'get' it once within the transaction, where I can see I get the object ba...

org.hibernate.NonUniqueObjectException Within GWT application using hibernate through gilead

Hello Guys, i am working on a project for college that uses GWT,Hibernate and Gilead. Basically for the moment users should be able to add friends and remove them. also a user can see if his or her friends are online or not. my trouble is that when i add a friend that is already related to another friend i get this error org.hibernate...

when to use Hibernate vs. Simple ResultSets for small application

I just started working on upgrading a small component in a distributed java application. The main application is a rather complicated applet/servlet combo running on JBoss and it extensively uses Hibernate for its DataAccess. The component i am working on however is very a very straightforward data importing service. Basically the wor...

Indexed element access in JPQL

Is it possible to do indexed element access in JPQL like in HQL : select o from Order o where o.items[0].id = 1234 I couldn't find something related in the JPA 2 specs, I am targeting EclipseLink JPA here, so if you come up with an EclipseLink solution, that's ok as well, although a JPQL standard solution is preferred. ...

Reusing an anonymous parameter in a prepared statement

I am customizing the insert SQL generated by hibernate and have hit an issue. When Hibernate generates the query by itself, it inserts data into the first two columns of the table, but this causes a database error since all four columns of the table are non-nullable. For the insert to be performed properly, it must insert the same data...

How can I add a complex order-by using Hibernate Criteria?

I'm using Hibernate criteria and would like to add an order-by clause that is functionally the same as this SQL: order by abs(dateSubmitted - 125234234) Where dateSubmitted is a long and the number subtracted from it will be user-supplied (as a date). I'm trying to order records by their 'distance' from a user supplied date. I've tri...

How to output two ddl files at the same time with using maven hbm2ddl plugin

Our application needs to use two different kinds of databases.One is oracle, the other is mysql and we want to use maven plugin hbm2ddl to generate the ddl file, and want to output the two ddl files at the same time, I don't know how to set the configuration in pom.xml. I tried to use this plugin twice, but it always generated one ddl fi...

Select all entities of exact class, but not derived from it using NHibernate Criteria API

I have two classes: Cat and DomesticCat, that extends Cat. I want to select all Cats, but no oneDomesticCat. How to do it using NHibernate criteria API? ...

hibernate distributed 2nd level cache options

Not really a question but I'm looking for comments/suggestions from anyone who has experiences using one or more of the following: EhCache with RMI EhCache with JGroups EhCache with Terracotta Gigaspaces Data Grid A bit of background: our applications is read only for the most part but there is some user data that is read-write and ...