Skip to content

Commit

Permalink
upgrade to Hibernate 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Mar 24, 2011
1 parent a98339a commit 2a525be
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 213 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ subprojects { project ->
mavenCentral() mavenCentral()
mavenRepo urls:"http://maven.springframework.org/release" mavenRepo urls:"http://maven.springframework.org/release"
mavenRepo urls:'http://maven.springframework.org/snapshot' mavenRepo urls:'http://maven.springframework.org/snapshot'
mavenRepo name:'jboss-public', urls:'http://repository.jboss.org/nexus/content/groups/public-jboss/'
} }
dependencies { dependencies {
// Groovy // Groovy
Expand Down Expand Up @@ -114,7 +115,7 @@ subprojects { project ->
// Specs // Specs
compile 'javax.servlet:servlet-api:2.5' compile 'javax.servlet:servlet-api:2.5'
compile 'javax.transaction:jta:1.1' compile 'javax.transaction:jta:1.1'
compile 'javax.persistence:persistence-api:1.0' compile 'org.hibernate.java-persistence:jpa-api:2.0-cr-1'


// Spring // Spring


Expand Down
8 changes: 3 additions & 5 deletions grails-hibernate/build.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ dependencies {
} }


// Hibernate related // Hibernate related
compile 'org.hibernate:hibernate-annotations:3.4.0.GA', compile 'org.hibernate:hibernate-core:3.6.1.Final'
'org.hibernate:hibernate-commons-annotations:3.1.0.GA',
'org.hibernate:hibernate-core:3.3.1.GA'
compile 'javassist:javassist:3.11.0.GA' compile 'javassist:javassist:3.11.0.GA'






runtime 'org.hibernate:hibernate-validator:3.1.0.GA', runtime 'org.hibernate:hibernate-validator:4.1.0.Final',
'org.hibernate:hibernate-ehcache:3.3.1.GA', 'org.hibernate:hibernate-ehcache:3.6.1.Final',
'antlr:antlr:2.7.6' 'antlr:antlr:2.7.6'




Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1119,13 +1119,13 @@ else if (paginationEnabledList) {
criteria.setFirstResult(0); criteria.setFirstResult(0);
criteria.setMaxResults(Integer.MAX_VALUE); criteria.setMaxResults(Integer.MAX_VALUE);
criteria.setProjection(Projections.rowCount()); criteria.setProjection(Projections.rowCount());
int totalCount = ((Integer)criteria.uniqueResult()).intValue(); int totalCount = ((Number)criteria.uniqueResult()).intValue();


// Drop the projection, add settings for the pagination parameters, // Drop the projection, add settings for the pagination parameters,
// and then execute the query. // and then execute the query.
criteria.setProjection(null); criteria.setProjection(null);
for (Iterator<Order> it = orderEntries.iterator(); it.hasNext();) { for (Order orderEntry : orderEntries) {
criteria.addOrder(it.next()); criteria.addOrder(orderEntry);
} }
if (resultTransformer == null) { if (resultTransformer == null) {
criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
Expand Down Expand Up @@ -1200,17 +1200,17 @@ else if (paginationEnabledList) {
return name; return name;
} }


if (targetBean.isReadableProperty(name.toString())) { if (targetBean.isReadableProperty(name)) {
ClassMetadata meta = sessionFactory.getClassMetadata(targetBean.getWrappedClass()); ClassMetadata meta = sessionFactory.getClassMetadata(targetBean.getWrappedClass());
Type type = meta.getPropertyType(name.toString()); Type type = meta.getPropertyType(name);
if (type.isAssociationType()) { if (type.isAssociationType()) {
String otherSideEntityName = String otherSideEntityName =
((AssociationType) type).getAssociatedEntityName((SessionFactoryImplementor) sessionFactory); ((AssociationType) type).getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
Class oldTargetClass = targetClass; Class oldTargetClass = targetClass;
targetClass = sessionFactory.getClassMetadata(otherSideEntityName).getMappedClass(EntityMode.POJO); targetClass = sessionFactory.getClassMetadata(otherSideEntityName).getMappedClass(EntityMode.POJO);
BeanWrapper oldTargetBean = targetBean; BeanWrapper oldTargetBean = targetBean;
targetBean = new BeanWrapperImpl(BeanUtils.instantiateClass(targetClass)); targetBean = new BeanWrapperImpl(BeanUtils.instantiateClass(targetClass));
associationStack.add(name.toString()); associationStack.add(name);
final String associationPath = getAssociationPath(); final String associationPath = getAssociationPath();
createAliasIfNeccessary(name, associationPath); createAliasIfNeccessary(name, associationPath);
// the criteria within an association node are grouped with an implicit AND // the criteria within an association node are grouped with an implicit AND
Expand Down Expand Up @@ -1306,8 +1306,7 @@ private String getAssociationPath() {
if (fullPath.length() > 0) fullPath.append("."); if (fullPath.length() > 0) fullPath.append(".");
fullPath.append(propertyName); fullPath.append(propertyName);
} }
final String associationPath = fullPath.toString(); return fullPath.toString();
return associationPath;
} }


private boolean isCriteriaConstructionMethod(String name, Object[] args) { private boolean isCriteriaConstructionMethod(String name, Object[] args) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
*/ */
package org.codehaus.groovy.grails.orm.hibernate.cfg; package org.codehaus.groovy.grails.orm.hibernate.cfg;


import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.codehaus.groovy.grails.commons.AnnotationDomainClassArtefactHandler; import org.codehaus.groovy.grails.commons.*;
import org.codehaus.groovy.grails.commons.ArtefactHandler;
import org.codehaus.groovy.grails.commons.DomainClassArtefactHandler;
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsClass;
import org.codehaus.groovy.grails.commons.GrailsDomainClass;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
Expand All @@ -35,6 +26,10 @@
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.FilterDefinition; import org.hibernate.engine.FilterDefinition;


import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/** /**
* Allows configuring Grails' hibernate support to work in conjuntion with Hibernate's annotation * Allows configuring Grails' hibernate support to work in conjuntion with Hibernate's annotation
* support. * support.
Expand Down Expand Up @@ -132,6 +127,8 @@ public SessionFactory buildSessionFactory() throws HibernateException {
*/ */
@Override @Override
protected void secondPassCompile() throws MappingException { protected void secondPassCompile() throws MappingException {
final Thread currentThread = Thread.currentThread();
final ClassLoader originalContextLoader = currentThread.getContextClassLoader();
if (!configLocked) { if (!configLocked) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsAnnotationConfiguration] [" + domainClasses.size() + "] Grails domain classes to bind to persistence runtime"); LOG.debug("[GrailsAnnotationConfiguration] [" + domainClasses.size() + "] Grails domain classes to bind to persistence runtime");
Expand All @@ -145,7 +142,7 @@ protected void secondPassCompile() throws MappingException {
final String fullClassName = domainClass.getFullName(); final String fullClassName = domainClass.getFullName();


String hibernateConfig = fullClassName.replace('.', '/') + ".hbm.xml"; String hibernateConfig = fullClassName.replace('.', '/') + ".hbm.xml";
final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ClassLoader loader = originalContextLoader;
// don't configure Hibernate mapped classes // don't configure Hibernate mapped classes
if (loader.getResource(hibernateConfig) != null) continue; if (loader.getResource(hibernateConfig) != null) continue;


Expand All @@ -159,7 +156,14 @@ protected void secondPassCompile() throws MappingException {
} }
} }


super.secondPassCompile();
try {
currentThread.setContextClassLoader(grailsApplication.getClassLoader());
super.secondPassCompile();
} finally {
currentThread.setContextClassLoader(originalContextLoader);

}
configLocked = true; configLocked = true;
} }


Expand Down
Loading

0 comments on commit 2a525be

Please sign in to comment.