hibernate

Problem with tables with foreign keys

I am trying to make a web application using Netbeans 6.5, MySQL 5.1, JSF, hibernate 3.2 and GlassFish. I want to insert the contents of a form in the database; it works fine when the table doesn't have foreign keys but it doesn't work when they do have them. I tried using Hibernate, and also using an SQL query directly, but it can't get ...

How can I map a different parent class in different projects to the same shared child class?

Summary: I have two projects using the same database relation. I would like to map the relation differently in each project, using the same child class but different parent classes. Detail: I have two projects, ADMIN and SERVICE. ADMIN allows the persisted object Promo to be configured. SERVICE will read Promo. We're using Spring...

Filtering out log4j messages from third-party frameworks?

How do I filter log messages from external third party frameworks? I am using Hibernate and Spring framework and I would like to suppress the logs so that only my log4j logs appears. ...

Two queries instead of one, when using LockOption.UPGRADE

I have two entities with one-directional OneToOne relationship. EAGER fetch type is specified. When I load parent entity by id, one sql inner join query is executed. This is right behavior. But when I specify LockOption.UPGRADE, the parent and child entities are loaded in two different queries instead of one. Why this happens? ...

HIbernate Entity Manager: How to cache queries?

I am using the Hibernate 3.5.1 and EntityManager for data persistence (with JPA 2.0 and EHCache 1.5). I can obtain the query by the following code: EntityManager em; ... Query query = em.createQuery(...); ... Now, the problem is that EntityManager's createQuery() method returns javax.persistence.Query which, unlike org.hibernate.Query...

More condition on hibernate left join clause

How to achieve subquery in hibernate criteria left join? I tried in this way, DetachedCriteria subquery = DetachedCriteria.forClass( Comment.class, "comment").add(Restrictions.eq("comment.divisionId", divisionId)); subquery.setProjection(Projections .groupProperty("comment.commentId")); Session ses...

Spring Transaction propagation issue

I am using Transaction management with Spring and Hibernate. My situation is as follow: I have got bean A which is sorrounded by transaction and it call bean B which is defined with transaction including the attribute 'PROPAGATION_REQUIRED' B in this case doesn't open new transaction but uses the exsiting one (saw in the logs: 'Partici...

How to create a Generic DAO class using Hibernate Context sessions

I'm trying to implement a Generic DAO using the Hibernates Context Sessions. Following was my shot:| import java.io.Serializable; public interface GenericDao<T, ID extends Serializable> { /** Persist the newInstance object into database */ ID create(T newInstance); /** * Retrieve an object that was previously persisted to the da...

Java type casting for hibernate

Yes, I know we can upcast or downcast in Java. But the type of the instance doesn't really seems to be change and it's giving me a problem. E.g. class Foo{ int a, b; .. constructers, getters and setters } class FooDTO extends Foo { ... } FooDTO dto = FooDTO(1,2); Foo parent = (Foo) dto; in hibernate, when saving the "parent", it's ...

lazy="true" for many to one equalivalant in hibernate 3

What is the equivalant way to configure lazy="true" in hibernate3.? While fetching object i will fetch the associated object using fetch concept.So in mapping itself i need to specify it. ...

Problem with Hibernate template

Hello, I use hibernate for save, update and delete data in my database, but I have some problems. For example I have a request for save or update my data in database getHibernateTemplate().saveOrUpdate(client); getHibernateTemplate().flush(); When I launch my server (TomCat) for the first and I save my data, all is okay, in my data...

Record store in MySQL database with Hibernate

Hi Everyone, I'm now working on a project and wants to save Dummies-Daten/Werte in simple database with Hibernate and then read again. So I have few experience with Hibernate. How can I do that? Thanks in advance Luky ...

How to implement a 3 Many-to-Many relationship with Hibernate?

Hi, I'm not 100% sure this is only a Hibernate issue as this might be a more abstract decision but I'll give it a try. Since the problem description is a bit lengthy I'll first state that what I'd like to do is see if I can change the implementation to something which more resembles a Best practice implementation then this. I have 3 ent...

Handling NVARCHAR columns with MS SQL Server and Hibernate

I have an application which uses MS SQL Server 2005 as the DBMS and jTDS as the JDBC driver. All the columns storing text are of type VARCHAR. A sendStringParametersAsUnicode=false parameter has been specified for the driver in order to prevent it sending all strings as unicode (which would cause an index scan instead of index seek for i...

Using OpenSessionInViewInterceptor to avoid LazyInitializationException

First I need to acknowledge the fact that I'm new to EJB, JPA and Spring, so many of the things I believe as true could be wrong. I'm building an EJB application where there's an stateless session bean used to retrieve many JPA (Hibernate) entities. The problem, which I believe is a widespread problem, is that I cannot traverse the rela...

Hibernate get single row from the table with maximum field value

Hi Guys, In Hibernate, how can I get single row from the table with maximum field value? Thanks ...

Hibernate: cant get the associated List retrieved

Hi An entity X has a list of entity Y and the entity Y has an instance of entity Z. The relation between X to Y is OneToMany and the relation between Y to Z is ManyToOne. I want to retrieve X and have all the associated entities retrieved with them as well. What HQL query do I write so that I get the whole chain retrieved all at once...

How to intercept all Hibernate sessions when they're created (Spring / Grails environment)

Is there a way of intercepting all new Hibernate sessions when they're created? I need to access each Session instance to enable a Hibernate filter with a parameter. The only solution I've gotten working has involved wrapping the SessionFactory, but this involved a lot of semi nasty hacks as well as it required me to implement around 6...

What is a practical process for doing data transformation on a live system when hibernate + code generation is used?

I have an existing database defined via HBM.XML files (code and sql dml generated via Hibernate tools), and am looking for a practical way to perform data transformation on existing data. So supposed the following: The original table is defined with a single FK; there is existing data. The revised table is defined with two FKs; the two...

JPA: caching queries

Hi! I'm using JPA to load and persist entities in my JEE-based web application. Hibernate is used as an implementation of JPA, but I don't use Hibernate-specific features and only work with pure JPA. Here is some DAO class, notice getOrders method: class OrderDao { EntityManager em; List getOrders(Long customerId) { Query q =...