hibernate

I am using spring to load hibernate, need optimized code for findbyNamedQuery(String query)

I am using spring to load hibernate, need optimized code for findbyNamedQuery(String query) ...

How can I retrieve a collection property using criteria Api

I want to retrieve a collection property using criteria public class A { private Collection<B> property // getters and setters } public class B { private int status // getters and setters } My criteria code is as follows: Criteria cr = getSession().createCriteria(A.class) cr.createA...

Hibernate saving User model to Postgres

I'm using Postgres via Hibernate (annotations), but it seems to be falling over dealing with a User object: 12:09:16,442 ERROR [SchemaExport] Unsuccessful: create table User (id bigserial not null, password varchar(255), username varchar(255), primary key (id)) 12:09:16,442 ERROR [SchemaExport] ERROR: syntax error at or near "User" I...

Problem in Decimal Value

private static DecimalFormat decimalFormat = new DecimalFormat("0.0000000000"); public static void main(String[] args) { String str ="73.71" ; BigDecimal decimal= new BigDecimal(str); System.out.println("Tesing1 " + decimal.floatValue()/10000); System.out.println("Tesing2 " + decimal.f...

java and hibernate

if client updates hibernate database ,then how can the server access the updated data at that moment without restarting server? ...

Learning resource for Configuring Hibernate JPA 2.0 on Glassfish server

Hi guys, I am trying to create a new JEE project using hibernate and JPA 2.0 on the glass fish server.Can you guys provide me some resources to configure the above so that they work seemlessly. I have tried using netbeans and generated the persistence unit by using the hibernate provider,but i end up getting this error javax.persi...

Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

Hi folks, I have got almost the same problem like that user. In my situation I load one entity from db, I convert this entity into a DataTransferObject, then I want to edit one attribute, after that I convert it back into an entityObject, then I update that entity and hibernate throws following error: Hibernate Error: org.hibernate.No...

Hibernate session.get() Problem with UUID string ID

I am having a problem with Hibernate. The primary key of ID in mysql table is UUID style String. e.g.08fe2a75-5d40-4645-896d-aab2a3ac96b8 But I can not use session.get() to fetch out the data for some reason. Software software=(Software)session.get(Software.class, id); It seems ok with integer IDs. Please advise ...

Why does Hibernate throw exception "java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()"?

Why does the UniqueConstraint annotation in the following Hibernate mapping declaration cause the exception java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name() (see below for stack trace)? Note that when I remove the UniqueConstraint annotation, Hibernate does not throw the exception and Spring successfully creates th...

Is it possible to share configuration from persistence.xml?

I have one persistence unit configured in my persistence.xml but i have two databases. Those databases are identical, regarding the schema. What i am trying to do is: Persistence.createEntityManagerFactory("unit", primaryProperties); Persistence.createEntityManagerFactory("unit", secondaryProperties); The properties contain different ...

Hibernate not creating table when using Spring DAO

I'm trying to use Spring DAO with Hibernate for a web application. When I try to persist information in the DAO using getHibernateTemplate().save("bar", bar); I get the following in Tomcat: org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [com.enw.foo.domain.Bar]; nested exception is org.hibernate...

JPA Best Practice: Static Lookup Entities

Imagine, an Event entity references a Status Entity: @Entity @Table(name = "event") public class Event() { @Id @Column(name = "id", nullable = false) private long id; ... @ManyToOne @JoinColumn(name = "status_code", nullable = false) private Status status; } @Entity @Table(name = "status") public class Status() { @Id ...

Hibernate loading all entities utilizing 1st or 2nd level cache

We have an entire table of entities that we need to load during a hibernate session and the only way I know to load all entities is through an HQL query: public <T> List<T> getAllEntities(final Class<T> entityClass) { if (null == entityClass) throw new IllegalArgumentException("entityClass can't be null"); List<T> list ...

Migrating a custom persistence layer to hibernate3

So, very soon, I will be part of a migration that will move a home-rolled persistence layer (circa any good, popular ORM) to hibernate3. However, at the same time that this migration happens, developers will be working to implement new business logic atop the current persistence layer, hence working against the migration! Does anyone hav...

How would you declare the OneToMany member variable

Which of the following declaration would be the right one to choose for allocating the right amount of memory. Option 1 has an initial collection capacity of 0 and Option 2 has an initial capacity of 10 and Option 3 doesn't declare anything. If the underlying ORM provider loads these object eventually, wouldn't it be using a setEmails(....

Can I use CompositeId on subclasses of Discriminated Entity Hierarchy?

I have a entity hierarchy has single table for all subclasses strategy. And I want to use each properties - mapped @ManyToOne - as primarykey. When I put @Id annotation, I'm getting this error: java.lang.ClassCastException: org.hibernate.mapping.SingleTableSubclass cannot be cast to org.hibernate.mapping.RootClass So how can I provide...

Spring/Hibernate: Do you have to load entities to use it after saving?

Hi all, I have a database model with two tables: Session and ScriptExecution which are associated with a one-to-many relationship: public class ScriptExecution implements Serializable { @ManyToOne @PrimaryKeyJoinColumn private Session session; ... } public class Session implements Serializable { @OneToMany(fetch=FetchType.EAGER...

JPQL ORDER BY clause with parameter

I'm trying to write a JPQL Query with an ORDER BY clause: query = "SELECT c FROM item ORDER BY c.name ASC" I would like to set an "order" parameter, whose value would be either "ASC" or "DESC": query = "SELECT c FROM item ORDER BY c.name :order" And then in my implementation: query.setParameter("order", "ASC"); This is when I ge...

Concurrent updates handling in hibernate..

Presently we are using JDBC in the data layer and planning to replace it with hibernate.I am new to Hiberante and not sure how hiberante handles concurrency. Can somebody explain me if we use spring for the transaction management, how concurrent updates will be handled by hibernate (In memory automatic version management of hibernate) or...

hibernate interceptor post save?

i need to intercept post save for an entity in hibernate, but all what i found was on save, which is dealing with the entity before being saved, and there's a postFlush method which return a huge lazy iterator, that i can't understand how to use it, please suggest me a way to catch entity after hibernate save or update, Regards, ...