hibernate

@OneToMany association joining on the wrong field

I have 2 tables, devices which contains a list of devices and dev_tags, which contains a list of asset tags for these devices. The tables join on dev_serial_num, which is the primary key of neither table. The devices are unique on their ip_address field and they have a primary key identified by dev_id. The devices "age out" after 2 we...

In JPA and Spring can a persistence unit be created on the fly?

So apparently we have the need to create persistence units on the fly. Basically we have this web service and a bunch of identical schemas with identical domain classes. We want to be able to pass a query to the web service where the context path matches a schema. The first time that the service is queried then pass in that schema name a...

Hibernate is rounding my double ?

Hi, I've got a double which I'm trying to save to a postgres numeric column. The value I'm trying to save is 151.33160591125488, and I've verified that this is in fact the argument being received by Hibernates internals pre-insert. However the value in the database post insert is 151.331605911255, ie it's been rounded to 12dp. I know...

Can HQL substract or sum date fields?

A have two entities. For example timing settings and orders. @Entity public class TimingSettings{ @Basic private Long orderTimeout = 18000; //for example 18000 sec .... } @Entity public class Order{ @Basic @OneToOne private TimingSettings timingSettings; @Temporal(value = TemporalType.TIMESTAMP) @Co...

Datetime in java and default datetime mapping in hibernate

Hello good people, I need some little help about a confusion i'm having. since i came from C# .NET i was expeting java to have something similar to C# DateTime. While i manage to create a helper method to convert string representation of date like eg "2009-10-16 11:14:34" to date object. here is the method public static Date convertT...

LazyInitialization Exception

I have 2 Hibernate objects : Dero and Motif. a Dero has a set of Motif. I load a Dero object from the DB fine. but when I try to access its set of Motif : assertEquals(dero.getMotifRefus(),deroFromDB.getMotifRefus()); I get an exception : org.hibernate.LazyInitializationException: failed to lazily initialize a collection of rol...

Update father on interceptor

My model: public class Father { Set<Son> sons = new HashSet<Son>(); String name = null; Date lastSonModifyDate = null; // ... other fields and setters/getters } public class Son { Father father = null; String name = null; Date lastModifyDate = null; // ... other fields and setters/getters } Use case: There is in ...

Hibernate Annotations generating query that produces SQLGrammarException

Still duking it out with Hibernate... I'm using Hibernate-Annotations instead of hbm.xml files for my beans, but I'm currently running into a problem where the SQL that Hibernate is generating references nonexistent database columns. For instance, here is the code: Query q = session.createQuery("FROM Status ORDER BY post_date DESC"); ...

Looking for *working* Hibernate examples

I have been scouring the intertubes for working somewhat recent Hibernate examples. I understand it well on a conceptual level, but I'm having trouble throwing together a "hello world" program, because every one I find doesn't build for me. I should be able to adapt to different entity relationships after that, but I would settle for a...

caching spring/hibernate webapp

I have a website that allows searches for lists of content in various ways, for instance "show stuff created by user 523 ordered by date" or "show a list of the most recent 10 posts." I use Hibernate for my ORM, and Hibernate provides a cache for objects. For lists of objects, though, like the front page list of most recent content, I'...

Hibernate Unable to Start On Large-Scale Database

Hello, I have been using Hibernate + HSQLDB on my desktop for developing a database adapter for my application. For legacy reasons, the IDs are generated by the application as strings. All was working fine then. Now, we have a pre-prod database, with a bit more than a million records. I had to do some changes (e.g. identifier too long)...

INSERT LOW_PRIORITY or INSERT DELAYED in Hibernate

Hi guys, How do I do a low_priority or delayed insert into a MySQL table with Hibernate? In my logging routine I want to insert the log info to a table in my database for further analysis. But I don't care about how long it takes for the insert to be done, so usually I would say INSERT LOW_PRIORITY INTO LogEntry (level, title, full) VA...

Design pattern for translatable Hibernate models

I have a Hibernate model that (simplified) looks like this: public class CoverageLine { private Long id; private String coverageText; private boolean coveragePresetTo = true; private OnNewPolicy onNewPolicy = OnNewPolicy.SHOW; } I need coverageText to be translatable (by the end-user) into arbitrarily many languages, but using...

ORM for Oracle pl/sql

Hi, I am developing a enterprise software for a big company using Oracle. Major processing unit is planned to be developed in PL/SQL. I am wondered if there is any ORM like Hibernate for Java, but the one for PL/SQL. I have some ideas how to make such a framework using PL/SQL and Orcale system tables, but it is interesting - why no one h...

Is there a helper to know whether a property has been loaded by Hibernate?

I need a helper to know whether a property has been loaded as a way to avoid LazyInitializationException. Is it possible? @Entity public class Parent { @OneToMany private List<Child> childList; } @Entity public class Child { } "select distinct p from Parent p left join fetch p.childList"; // Answer goes here // I want to avo...

java.util.ConcurrentModificationException on CollectionOfElements

Hi. I seem to get a ConcurrentModificationException when I have a CollectionOfElements inside an Embedabble. If would like to have it like that, however If I change Route from Embedabble's to Entity than everything works fine. I have even tried adding @Version, but that doesn't seem to work. Here are a snippet of my classes. Kart.java:...

@Immutable vs @Entity(mutable=false) in Hibernate

What is the difference between the two if any? Should 1 or both be used on an entity? ...

Issue Using Hibernate Criteria object with composite key

NOTE: I have changed the details provided due to comments provided. The new technical details are actually code that I am trying to run currently. I have a weird problem going on currently with one of my OneToMany / ManyToOne bidirectional relationships. In the parent table I have a long which is the identifier and the child also h...

Does Fluent-Hibernate exist?

Is there something like Fluent-NHibernate for the original Java Hibernate? If not, why not? Are there any language-specific limitations? ...

Hibernate cannot recover after socket has timed out

I have an application that uses Hibernate to connect to my MySQL database. I'm just having a weird problem with timeouts. Let's say that the socket timeout in MySQL's configurations is set to one hour. After an hour of inactivity, the socket times out as expected. The problem is that Hibernate doesn't seem to be able to handle the socket...