hibernate

How to solve circular reference in json serializer caused by hibernate bidirectional mapping?

I am writing a serializer to serialize POJO to JSON but stuck in circular reference problem. In hibernate bidirectional one-to-many relation, parent references child and child references back to parent and here my serializer dies. (see example code below) How to break this cycle? Can we get owner tree of an object to see whether object ...

Hibernate restrictions with joins

I trying to build a Criteria made up of various components. Imagine the mapped classes below. class Thing { Inner inner; String x; } class User { Id; // mapped as id. String first; // indexed columns etc String last; } I would like to create a query (aka Criterion) for Things where User.first=@1 and User.last=@2. I ...

How do I sort a linked list in hql?

Same question as this, only I'd like to do it in Hibernate (using grails if that matters). So the domain class looks like this class LinkedElement { LinkedElement precedingElement String someData } and I'd like to query all elements in their linked order (where the first LinkedElement has null as the precedingElement). Is this po...

javax.servlet.jsp.JspException: Cannot create iterator for this collection

hi I came across this error Plz help me out ...

Hibernate: composite-element results in delete+insert on every commit

Here's a part of my mapping: <hibernate-mapping package="trx.domain"> <class name="Master" table="master" dynamic-update="true" dynamic-insert="true"> <set name="attributes" table="attribute" lazy="true" cascade="all" batch-size="10"> <cache usage="nonstrict-read-write" /> <key> ...

Best type for IP-address in Hibernate Entity?

What is the best type for storing IP-addresses in a database using Hibernate? I though Byte[] or String, but is there a better way, or what do you use? @Column(name = "range_from", nullable = false) public Byte[] getRangeFrom() { return rangeFrom; } public void setRangeFrom(Byte[] rangeFrom) { this.rangeFrom = rangeFrom; } ...

Hibernate date mapping problem

I am using a SQL Server database and Hibernate. I have the following problem related to storing dates: I have the following code: String hql = "select user from User user where user.createDate = :date"; Query query = HibernateUtil.getSession().createQuery(hql); Date date2 = DateHelper.getEndOfDay(new Date());//this returns 2010-07-27 2...

Error in my hibernate request

hello i have an error when i execute a request with hibernate ERROR ast.ErrorCounter (ErrorCounter.java:33) - line 1:22: expecting IDENT, found '*' my dao: public List rechercheValeurTarifs() throws Exception { List tarifs = null; try{ tarifs = getHibernateTemplate().find("SELECT FE_TARIF_IDF.* " + ...

Error: with request Oracle, hibernate

hello, i have an error with my hibernate request Hibernate operation: could not execute query; bad SQL grammar [select tarifs0_.D_ANNE as D1_33_, tarifs0_.D_NZONE as D2_33_, tarifs0_.D_CTYPE_LOCAL as D3_33_, tarifs0_.D_NTARIF_NORMAL as D4_33_, tarifs0_.D_NTARIF_REDUIT as D5_33_, tarifs0_.D_NSURFACEMIN as D6_3...

java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator Seam weblogic 10.3

Hi guys, I have a big problem with Hibernate (use with seam) on weblogic 10.3. When I publish my application, I get this error: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations....

Setting subclass primary key as auto_increment using JPA 2 annotations

Hi. I'm trying to generate a database schema for my project using hbm2ddl. I'm using JPA 2 annotations to specify how the schema should look like. Right now I'm having some issues with inherited id's. I have an abstract super class, let's call it AbstractSuperClass, which looks like this: @Entity @Inheritance(strategy=InheritanceType....

Exception Caught Too Early

Background: Hibernate connects to a database using a username and password entered into a GUI. Upon failure, instead of propagating the error up as an exception, it comes out as a stack trace in the logger. I don't know where the exception is being caught at. Also a tiny bit troubling is the following block: if (reason != null) { ...

Hibernate projects and Building with maven

I'm trying to build a relative easy project and include Hibernate with maven. I'm trying to use the latest version of Hibernate (3.5.4-Final). It seems that the JBoss folks have changed their maven repository recently, and I'm having some problems getting my maven build to work. I have found a lot of information on the web and here, but...

JPA (hibernate) onetomany relation

Hello, I am not sure what I am missing to make a bidirectional onetomany relationship (hibernate engine). A scaled down version of the domain model: class Person { @OneToMany(mappedBy="personFrom", cascade = CascadeType.PERSIST) public List<Relationship> relationships; } class Relationship { @ManyToOne public Person personFrom;...

DDD and storing complex Value Object in db using Hibernate

In the sample DDD project written by Eric Evans (http://domaindrivendesign.org/examples) there is a Cargo class which is an entity object and is mapped to db table using hibernate. That Cargo domain object consists of several value objects one of which is Delivery. This Delivery value object is quite complex as it has some 10 fields. Non...

Hibernate optimistic locking..how it works??

Hi, I was reading the below blog about hibernate optimistic locking. I am planning to use it with hibernate. But, I have one concern. we have java code and c++ code, both connect to one database. While, java code can use hibernate to achieve optimistic locking, I want to make the c++ code do the same thing. Also, c++ code is using some ...

Mysql custom sequence generator ( like oracle)

I want to have two auto_increment column's per table, but mysql allows only one auto_increment columns. So, I tried replicating the oracle sequence using my own table. Here is the schema. create table logical_id_seq ( logical_id int auto_increment, primary key(logical_id) ); create table mytable ( physical_id int auto_incr...

What is the proper way to ensure EntityManager connections are closed?

There are 19 methods in our DAO layer, each is some variation of this: public TicketProp saveTicketProp(TicketProp prop) { EntityManager em = this.emf.createEntityManager(); try { em.getTransaction().begin(); prop = (TicketProp) em.merge(prop); em.getTransaction().commit(); return prop; } fina...

Hibernate usage in a Servlet environment

I'm trying to create a domain object that contains objects in a read-only fashion but be able to modify which objects it points to. So in the example below I would like Hibernate to handle populating the Account and Category objects but I don't want to ever update those objects. However I may wish to change which Account or which Categ...

Hibernate, how to model this relationship

I have the below tables. create table logical_id_seq ( logical_id int auto_increment, primary key(logical_id) ); create table mytable ( physical_id int auto_increment, logical_id int not null references parent(logical_id), data varchar(20), primary key(physical_id) ); The second table uses first table auto-gen...