hibernate

JPQL to SQL converter

Is it possible to access the SQL which is generated by JPQL? I would like to use the SQL to later create a view for my purposes. I am using Hibernate if it matters. ...

How to join tables in unidirectional many-to-one condition ?

I have two classes . for example : class A { public Long id ; } class B { public Long id ; public A a ; } B and A has many to one relationship. I can get List of B like this : "from B b left join b.a a where a.id > 10 and b.id > 10 " . But how can I get List of A under the same join conditions ? I can't navigate A to B , Is there an...

Maven cannot exec a jar project because the mess with transitive dependency

I have 5 maven projects: simple-model, simple-weather, simple-persist, simple-webapp and simple-console. (They are from the Maven Definitive Guide book). The simple-console depends on simple-weather and simple-persist. simple-persist and simple-weather both depend on simple-model: simple-console ---> simple-weather ----> simple-model ...

Force update in Hibernate

How can I force Hibernate to update an entity instance even if the entity is not dirty? I'm using Hibernate 3.3.2 GA, Hibernate Annotations and Hibernate EntityManager btw. I really want Hibernate to execute the generic UPDATE statement even if no property on the entity has changed. I need this because some event listeners need to get i...

Value of 0 in Hibernate IndexColumn mapped with base=1

We are using Hibernate Annotations 3.4.0GA and Hibernate Core 3.3.2.GA (also known as the current stable versions) against an Oracle database We have a One-to-Many mapping with base=1 which worked fine for a loooong time, yet last week we found some entries in the database where the index column contained a value of 0 which caused all k...

How much overhead do frameworks like Hibernate bring?

Developers are sometimes scathing of mult-tier Enterprise web applications... 'Enterprise' is viewed by some as synonymous with slow, bloated and resource-hungry. Do frameworks such as Hibernate actually bring in a non-trivial impact on performance compared to writing your own DAOs or other less abstracted approaches? By non-trivial I s...

Ordering results by computed value in Hibernate

Hello, I have a table Player with columns id, name, wins, games_played. I mapped it to a class Player. I want to do the following query in Hibernate (preferably with Criteria, if not possible with Criteria HQL will also help) select * from Player order by (wins / games_played) I expect to get List<Player> sorted by their win rat...

Remove dinamically an ordering to the result set in org.hibernate.Criteria

I have a Criteria with: Criteria criteria= session.createCriteria(Libro.class).addOrder( Order.asc("ID") ); However, when I want to get the rowcount fail: criteria.setProjection(Projections.rowCount()); because there is an order by in the query. How to remove dinamically the ordering in the Criteria? I mean, I am looking for like c...

how to implement lazy loading in hibernate

I have 3 tables with mapping CompanyRegistration <one-to-one name="referenceDb" class="com.hibermappings.ReferenceDb" cascade="all" constrained="false" /> <one-to-one name="registration" class="com.hibermappings.Registration" cascade="all" constrained="false" /> <prope...

Using a composite key in a many-to-many relationship in JPA

I've got the following situation: A User object has a Set of Permission objects (Set) Each User can have zero or more Permissions A Permission object has three fields The three fields of Permission up make up the composite key for that permission. As a consequence of this, we want exactly one instance in the DB of each Permission. ...

How can I set hibernate database config from outside config file?

I need to have hibernate database config set from outside text file, how can I do it? Is there some kind of method for this, or do I have to make my own? ...

Error when trying to use hibernate annotations.

The error I'm receiving is listed here. That's my HibernateUtil.java package com.rosejapan; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration;; public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // Create the Sess...

Ehcache - Distributed RMI not working

Hi, I have this strange problem with ehcache 2.0 that I hope someone can help me with. I have set up a cluster of two hosts, A and B. I can see that heartbeats are received at both ends, so I'm pretty sure the networking and multicast stuff is working. The problem is that is I put an element into the cache at host A, I can see in the lo...

Passing parameter to hbm2ddl

I have parametrized persistence.xml. I am trying to generate ddl schema using hbm2ddl. How can i pass parameters to this tool ? My persistence.xml looks like <property name="hibernate.connection.driver_class" value="${persistence.connection.driver.class}"/> <property name="hibernate.dialect" value="${persistence.dialect}"/> <property n...

define named query in orm.xml with jpa and hibernate

Hello, I'm trying to put my named queries in my orm.xml (put in META-INF with persistence.xml) but my orm.xml seems to be ignored by hibernate/jpa. When I try to create my named query with em.createNamedQuery("myQuery"), it returns that it can't find this query. I use annotation and I would like to externalize my named queries in orm...

Hibernate PostInsertEventListeners -Use Same Transaction as insert?

I have some hibernate code that performs an insert into the database, and on completion of that insert a customized PostInsertEventListener is fired. (Essentially a trigger to ensure that other records are updated appropriately) What I need to do is make the code inside the EventListener use the same transaction as the original insert, ...

Do I understand Spring @Transactional behaviour correctly?

I was hoping someone could confirm my understanding of transaction behaviour in a Spring service. Firstly, am I correct in believing that When using TransactionManager, all services which result in persistence to the database must be invoked from within a @Transactional method in order for the update to persist to the db? Eg, Given the...

Hibernate Update does Not Update Anything

Hello everyone, In theory, this code should set the new lock status to the users and get that written to the database: transaction = sess.beginTransaction(); String hql = "update User set locked=:newLockStatus where principalId in (:userIds)"; Query query = sess.createQuery(hql); query.setBoolean("newLockStatus", locked); query.setPara...

Hibernate Session is closed

Hi, When I call the method session.begin transaction as follows: //session factory is instantiated via a bean Session session = this.getSessionFactory().getCurrentSession(); session.beginTransaction(); Then I get the following exception message 6:13:52,217 ERROR [STDERR] org.hibernate.SessionException: Session is closed! at org.hibe...

Fetch last record in mysql

Hi I want fetch last record using hibernate criteria Can u help me? ...