Hibernate SVN: r14802 - entitymanager/tags.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-06-24 16:10:36 -0400 (Tue, 24 Jun 2008)
New Revision: 14802
Removed:
entitymanager/tags/v3_2_1_GA_CP02/
Log:
JBPAPP-918 - removing v3_2_1_GA_CP02; will create tag v3_2_1_GA_CP03 with internal version 3.2.1.GA_CP03 to distinguish from internal version (3.2.1.GA_CP02) in v3_2_1_GA_CP01
16 years, 5 months
Hibernate SVN: r14801 - in annotations/trunk: src/java/org/hibernate/annotations and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-06-24 15:03:32 -0400 (Tue, 24 Jun 2008)
New Revision: 14801
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Foobar.java
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/State.java
Removed:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
Modified:
annotations/trunk/doc/reference/en/modules/entity.xml
annotations/trunk/src/java/org/hibernate/annotations/Immutable.java
annotations/trunk/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
Log:
ANN-733
- Updated documentation
- Added some more tests and deleted obsolete test
- Modified PropertyBinder to throw AnnotationException in case @immutable is placed on a simple property
Modified: annotations/trunk/doc/reference/en/modules/entity.xml
===================================================================
--- annotations/trunk/doc/reference/en/modules/entity.xml 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/doc/reference/en/modules/entity.xml 2008-06-24 19:03:32 UTC (rev 14801)
@@ -2361,10 +2361,15 @@
</listitem>
</itemizedlist>
- <para><literal>@Immutable</literal> marks an entity as immutable. The
- entity may not be updated or deleted by the application. This allows
- Hibernate to make some minor performance optimizations.
- <literal>@Immutable</literal> must be use on root entities only.</para>
+ <para><literal>@Immutable</literal> marks an entity or collection as immutable. An immutable
+ entity may not be updated by the application. This allows
+ Hibernate to make some minor performance optimizations. Updates to an immutable
+ entity will be ignored, but no exception is thrown.
+ <literal>@Immutable</literal> must be used on root entities only. <literal>@Immutable</literal>
+ placed on a collection makes the collection immutable,
+ meaning additions and deletions to and from the collection are not allowed. A
+ <literal>HibernateException</literal> is thrown in this case.
+ </para>
<para><literal>@Persister</literal> lets you define your own custom
persistence strategy. You may, for example, specify your own subclass of
Modified: annotations/trunk/src/java/org/hibernate/annotations/Immutable.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/annotations/Immutable.java 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/java/org/hibernate/annotations/Immutable.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -4,8 +4,15 @@
import java.lang.annotation.*;
/**
- * Mark an Entity or a Collection as immutable
- * No annotation means the element is mutable
+ * Mark an Entity or a Collection as immutable. No annotation means the element is mutable.
+ * <p>
+ * An immutable entity may not be updated by the application. Updates to an immutable
+ * entity will be ignored, but no exception is thrown. @Immutable must be used on root entities only.
+ * </p>
+ * <p>
+ * @Immutable placed on a collection makes the collection immutable, meaning additions and
+ * deletions to and from the collection are not allowed. A <i>HibernateException</i> is thrown in this case.
+ * </p>
*
* @author Emmanuel Bernard
*/
Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -7,6 +7,7 @@
import org.hibernate.AnnotationException;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
+import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.common.reflection.XClass;
@@ -73,7 +74,7 @@
public void setColumns(Ejb3Column[] columns) {
insertable = columns[0].isInsertable();
updatable = columns[0].isUpdatable();
- //concsistency is checked later when we know the proeprty name
+ //consistency is checked later when we know the property name
this.columns = columns;
}
@@ -94,7 +95,10 @@
}
private void validateBind() {
- //TODO check necessary params for a bind
+ if (property.isAnnotationPresent(Immutable.class)) {
+ throw new AnnotationException("@Immutable on property not allowed. " +
+ "Only allowed on entity level or on a collection.");
+ }
}
private void validateMake() {
Deleted: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml 2008-06-24 19:03:32 UTC (rev 14801)
@@ -1,12 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-<!-- Generated Nov 9, 2006 6:27:53 PM by Hibernate Tools 3.2.0.beta7 -->
-<hibernate-mapping>
- <class name="org.hibernate.test.annotations.immutable.CountryHbm" mutable="false">
- <id name="id" column="id" type="java.lang.Integer">
- <generator class="native"/>
- </id>
- <property name="name"/>
- </class>
-</hibernate-mapping>
\ No newline at end of file
Modified: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -5,10 +5,15 @@
* @author Hardy Ferentschik
*/
import java.io.Serializable;
+import java.util.List;
+
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Immutable;
@Entity
@@ -16,7 +21,10 @@
@SuppressWarnings("serial")
public class Country implements Serializable {
private Integer id;
+
private String name;
+
+ private List<State> states;
@Id
@GeneratedValue
@@ -24,7 +32,6 @@
return id;
}
- @Immutable
public String getName() {
return name;
}
@@ -36,4 +43,15 @@
public void setName(String string) {
name = string;
}
+
+ @OneToMany(fetch = FetchType.LAZY)
+ @Cascade(org.hibernate.annotations.CascadeType.ALL)
+ @Immutable
+ public List<State> getStates() {
+ return states;
+ }
+
+ public void setStates(List<State> states) {
+ this.states = states;
+ }
}
Deleted: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -1,29 +0,0 @@
-//$Id$
-package org.hibernate.test.annotations.immutable;
-
-/**
- * @author Hardy Ferentschik
- */
-import java.io.Serializable;
-
-@SuppressWarnings("serial")
-public class CountryHbm implements Serializable {
- private Integer id;
- private String name;
-
- public Integer getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setId(Integer integer) {
- id = integer;
- }
-
- public void setName(String string) {
- name = string;
- }
-}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Foobar.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Foobar.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Foobar.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -0,0 +1,37 @@
+// $Id$
+package org.hibernate.test.annotations.immutable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.Immutable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Foobar {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Immutable
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Foobar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java 2008-06-23 21:25:21 UTC (rev 14800)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -1,9 +1,22 @@
//$Id$
package org.hibernate.test.annotations.immutable;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.AnnotationException;
+import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.annotations.fkcircularity.A;
+import org.hibernate.test.annotations.fkcircularity.B;
+import org.hibernate.test.annotations.fkcircularity.C;
+import org.hibernate.test.annotations.fkcircularity.D;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,56 +43,122 @@
tx.commit();
s.close();
- try {
- s = openSession();
- tx = s.beginTransaction();
- Country germany = (Country) s.get(Country.class, country.getId());
- assertNotNull(germany);
- germany.setName("France");
- s.save(germany);
- s.delete(germany);
- tx.commit();
- s.close();
-// fail();
- } catch (Exception e) {
- log.debug("success");
- }
+ // try changing the entity
+ s = openSession();
+ tx = s.beginTransaction();
+ Country germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ germany.setName("France");
+ assertEquals("Local name can be changed", "France", germany.getName());
+ s.save(germany);
+ tx.commit();
+ s.close();
+
+ // retrieving the country again - it should be unmodified
+ s = openSession();
+ tx = s.beginTransaction();
+ germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ assertEquals("Name should not have changed", "Germany", germany.getName());
+ s.close();
+
+// // try deletion
+// s = openSession();
+// tx = s.beginTransaction();
+// s.delete(germany);
+// tx.commit();
+// s.close();
+//
+// s = openSession();
+// tx = s.beginTransaction();
+// germany = (Country) s.get(Country.class, country.getId());
+// assertNotNull(germany);
+// assertEquals("Name should not have changed", "Germany", germany.getName());
+// s.close();
}
- public void testImmutableEntityWithMappingFile() throws Exception {
+ public void testImmutableCollection() {
+ Country country = new Country();
+ country.setName("Germany");
+ List states = new ArrayList<State>();
+ State bayern = new State();
+ bayern.setName("Bayern");
+ State hessen = new State();
+ hessen.setName("Hessen");
+ State sachsen = new State();
+ sachsen.setName("Sachsen");
+ states.add(bayern);
+ states.add(hessen);
+ states.add(sachsen);
+ country.setStates(states);
+
Session s = openSession();
Transaction tx = s.beginTransaction();
- CountryHbm country = new CountryHbm();
- country.setName("Germany");
s.persist(country);
tx.commit();
s.close();
-
+
+ s = openSession();
+ tx = s.beginTransaction();
+ Country germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ assertEquals("Wrong number of states", 3, germany.getStates().size());
+
+ // try adding a state
+ State foobar = new State();
+ foobar.setName("foobar");
+ s.save(foobar);
+ germany.getStates().add(foobar);
try {
- s = openSession();
- tx = s.beginTransaction();
- CountryHbm germany = (CountryHbm) s.get(CountryHbm.class, country.getId());
- assertNotNull(germany);
- germany.setName("France");
- s.save(germany);
- s.delete(germany);
tx.commit();
- s.close();
-// fail();
- } catch (Exception e) {
+ fail();
+ } catch (HibernateException e) {
+ assertTrue(e.getMessage().contains("changed an immutable collection instance"));
log.debug("success");
}
- }
-
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ assertEquals("Wrong number of states", 3, germany.getStates().size());
+
+ // try deleting a state
+ germany.getStates().remove(0);
+ try {
+ tx.commit();
+ fail();
+ } catch (HibernateException e) {
+ assertTrue(e.getMessage().contains("changed an immutable collection instance"));
+ log.debug("success");
+ }
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ assertEquals("Wrong number of states", 3, germany.getStates().size());
+ tx.commit();
+ s.close();
+ }
+
+ public void testMiscplacedImmutableAnnotation() {
+ try {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass(Foobar.class);
+ config.buildSessionFactory();
+ fail();
+ } catch (AnnotationException ae) {
+ log.debug("succes");
+ }
+ }
+
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
protected Class[] getMappings() {
- return new Class[] { Country.class };
+ return new Class[] { Country.class, State.class};
}
-
- @Override
- protected String[] getXmlFiles() {
- return new String[]{"org/hibernate/test/annotations/immutable/Country.hbm.xml"};
- }
}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/State.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/State.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/immutable/State.java 2008-06-24 19:03:32 UTC (rev 14801)
@@ -0,0 +1,34 @@
+// $Id$
+package org.hibernate.test.annotations.immutable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class State {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/State.java
___________________________________________________________________
Name: svn:keywords
+ Id
16 years, 5 months
Hibernate SVN: r14800 - annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-06-23 17:25:21 -0400 (Mon, 23 Jun 2008)
New Revision: 14800
Modified:
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/MapBinder.java
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java
Log:
JBPAPP-782
Modified: annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/MapBinder.java 2008-06-23 12:11:41 UTC (rev 14799)
+++ annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/MapBinder.java 2008-06-23 21:25:21 UTC (rev 14800)
@@ -7,7 +7,6 @@
import java.util.Random;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
-import javax.persistence.MapKey;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -282,7 +281,9 @@
String alias = "$alias$";
StringBuilder fromAndWhereSb = new StringBuilder( " from " )
.append( associatedClass.getTable().getName() )
- .append(" as ").append(alias).append(" where ");
+ //.append(" as ") //Oracle doesn't support it in subqueries
+ .append( " " )
+ .append( alias ).append( " where " );
Iterator collectionTableColumns = element.getColumnIterator();
while ( collectionTableColumns.hasNext() ) {
Column colColumn = (Column) collectionTableColumns.next();
Modified: annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java 2008-06-23 12:11:41 UTC (rev 14799)
+++ annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java 2008-06-23 21:25:21 UTC (rev 14800)
@@ -8,7 +8,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.2.1.GA";
+ public static final String VERSION = "3.2.1.GA.CP02";
private static Log log = LogFactory.getLog( Version.class );
static {
16 years, 5 months
Hibernate SVN: r14799 - search/branches/jboss_cache_integration.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-23 08:11:41 -0400 (Mon, 23 Jun 2008)
New Revision: 14799
Modified:
search/branches/jboss_cache_integration/build.xml
search/branches/jboss_cache_integration/common-build.xml
search/branches/jboss_cache_integration/pom.xml
Log:
Updated version and package info
Modified: search/branches/jboss_cache_integration/build.xml
===================================================================
--- search/branches/jboss_cache_integration/build.xml 2008-06-23 11:59:53 UTC (rev 14798)
+++ search/branches/jboss_cache_integration/build.xml 2008-06-23 12:11:41 UTC (rev 14799)
@@ -17,7 +17,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Search"/>
<property name="name" value="hibernate-search"/>
- <property name="version" value="3.1.0.NAVIN-SNAPSHOT"/>
+ <property name="version" value="3.1.0-SNAPSHOT"/>
<property name="javadoc.packagenames" value="org.hibernate.search.*"/>
<property name="copy.test" value="true"/>
<property name="javac.source" value="1.5"/>
Modified: search/branches/jboss_cache_integration/common-build.xml
===================================================================
--- search/branches/jboss_cache_integration/common-build.xml 2008-06-23 11:59:53 UTC (rev 14798)
+++ search/branches/jboss_cache_integration/common-build.xml 2008-06-23 12:11:41 UTC (rev 14799)
@@ -467,7 +467,7 @@
<artifact:pom id="maven.project" file="${pom.file}" />
<echo>GENERATED POM</echo>
- <artifact:install file="${jar.file.name}" overwrite="true">
+ <artifact:install file="${jar.file.name}">
<pom refid="maven.project"/>
</artifact:install>
</target>
Modified: search/branches/jboss_cache_integration/pom.xml
===================================================================
--- search/branches/jboss_cache_integration/pom.xml 2008-06-23 11:59:53 UTC (rev 14798)
+++ search/branches/jboss_cache_integration/pom.xml 2008-06-23 12:11:41 UTC (rev 14799)
@@ -2,10 +2,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-search</artifactId>
- <version>3.1.0.Beta1</version>
- <description>Hibernate Search</description>
+ <groupId>org.hibernate.sandbox</groupId>
+ <artifactId>hibernate-search-gsoc</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <description>Hibernate Search - JBoss Cache Integration Branch</description>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
16 years, 5 months
Hibernate SVN: r14798 - search/branches/jboss_cache_integration.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-23 07:59:53 -0400 (Mon, 23 Jun 2008)
New Revision: 14798
Removed:
search/branches/jboss_cache_integration/x.y
Log:
Removed dummy file
Deleted: search/branches/jboss_cache_integration/x.y
===================================================================
16 years, 5 months
Hibernate SVN: r14797 - in search/trunk: src/test/org/hibernate/search/test/embedded and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-06-23 04:23:48 -0400 (Mon, 23 Jun 2008)
New Revision: 14797
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/State.java
Modified:
search/trunk/doc/reference/en/modules/mapping.xml
search/trunk/src/test/org/hibernate/search/test/embedded/Author.java
search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java
Log:
* Added another test for @IndexedEmbedded
* Import cleanup
* Updated documtation - also OneToMany can be annotated with @indexedEmbedded
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2008-06-23 08:23:48 UTC (rev 14797)
@@ -349,7 +349,7 @@
...
}</programlisting>
- <para>Any <literal>@ManyToMany, @*ToOne</literal> and
+ <para>Any <literal>@*ToMany, @*ToOne</literal> and
<literal>@Embedded</literal> attribute can be annotated with
<literal>@IndexedEmbedded</literal>. The attributes of the associated
class will then be added to the main entity index. In the previous
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Author.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Author.java 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Author.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -5,7 +5,6 @@
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
-import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.DocumentId;
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Country.java 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Country.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -1,13 +1,21 @@
-//$
+// $Id:$
package org.hibernate.search.test.embedded;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.IndexColumn;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
/**
* @author Emmanuel Bernard
@@ -19,9 +27,16 @@
@GeneratedValue
@DocumentId
private Integer id;
+
@Field
private String name;
+ @OneToMany(fetch = FetchType.LAZY)
+ @IndexColumn(name = "list_position")
+ @Cascade(org.hibernate.annotations.CascadeType.ALL)
+ @IndexedEmbedded
+ private List<State> states = new ArrayList<State>();
+
public Integer getId() {
return id;
}
@@ -37,4 +52,12 @@
public void setName(String name) {
this.name = name;
}
+
+ public List<State> getStates() {
+ return states;
+ }
+
+ public void setStates(List<State> states) {
+ this.states = states;
+ }
}
Property changes on: search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.search.test.embedded;
+import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -22,6 +23,7 @@
/**
* @author Emmanuel Bernard
*/
+@SuppressWarnings("unchecked")
public class EmbeddedTest extends SearchTestCase {
public void testEmbeddedIndexing() throws Exception {
@@ -91,7 +93,39 @@
s.close();
}
+
+ public void testEmbeddedIndexingOneToMany() throws Exception {
+ Country country = new Country();
+ country.setName("Germany");
+ List states = new ArrayList<State>();
+ State bayern = new State();
+ bayern.setName("Bayern");
+ State hessen = new State();
+ hessen.setName("Hessen");
+ State sachsen = new State();
+ sachsen.setName("Sachsen");
+ states.add(bayern);
+ states.add(hessen);
+ states.add(sachsen);
+ country.setStates(states);
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( country );
+ tx.commit();
+
+
+ FullTextSession session = Search.createFullTextSession( s );
+ QueryParser parser = new QueryParser( "id", new StandardAnalyzer() );
+ Query query;
+ List result;
+
+ query = parser.parse( "states.name:Hessen" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find property in embedded", 1, result.size() );
+ s.close();
+ }
+
public void testContainedIn() throws Exception {
Tower tower = new Tower();
tower.setName( "JBoss tower" );
@@ -251,7 +285,8 @@
Product.class,
Order.class,
Author.class,
- Country.class
+ Country.class,
+ State.class
};
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Person.java 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Person.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -1,4 +1,4 @@
-//$
+// $Id:$
package org.hibernate.search.test.embedded;
/**
Property changes on: search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/org/hibernate/search/test/embedded/State.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/State.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/State.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -0,0 +1,37 @@
+// $Id:$
+package org.hibernate.search.test.embedded;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class State {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Field
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on: search/trunk/src/test/org/hibernate/search/test/embedded/State.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java 2008-06-23 08:23:48 UTC (rev 14797)
@@ -5,7 +5,6 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import javax.persistence.OneToOne;
import javax.persistence.ManyToOne;
import org.hibernate.search.annotations.DocumentId;
16 years, 5 months
Hibernate SVN: r14796 - entitymanager/tags.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2008-06-22 19:18:11 -0400 (Sun, 22 Jun 2008)
New Revision: 14796
Added:
entitymanager/tags/v3_2_1_GA_CP02/
Log:
JBPAPP-899 - Hibernate enitiymanager - getSingleResult() and fetch raise abusive NonUniqueResultException - ref: EJB-263
Copied: entitymanager/tags/v3_2_1_GA_CP02 (from rev 14795, entitymanager/branches/v3_2_1_GA_CP)
16 years, 5 months
Hibernate SVN: r14795 - entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2008-06-22 19:07:56 -0400 (Sun, 22 Jun 2008)
New Revision: 14795
Modified:
entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java
Log:
JBPAPP-899 - Hibernate enitiymanager - getSingleResult() and fetch raise abusive NonUniqueResultException - ref: EJB-263
Modified: entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java 2008-06-21 13:47:31 UTC (rev 14794)
+++ entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java 2008-06-22 23:07:56 UTC (rev 14795)
@@ -5,6 +5,8 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
@@ -82,7 +84,13 @@
em.throwPersistenceException( new NoResultException( "No entity found for query" ) );
}
else if ( result.size() > 1 ) {
- em.throwPersistenceException( new NonUniqueResultException( "result returns " + result.size() + " elements") );
+ Set uniqueResult = new HashSet(result);
+ if ( uniqueResult.size() > 1 ) {
+ em.throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements") );
+ }
+ else {
+ return uniqueResult.iterator().next();
+ }
}
else {
return result.get(0);
16 years, 5 months
Hibernate SVN: r14794 - in search/trunk/src: java/org/hibernate/search/backend and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-06-21 09:47:31 -0400 (Sat, 21 Jun 2008)
New Revision: 14794
Added:
search/trunk/src/test/org/hibernate/search/test/session/Domain.java
search/trunk/src/test/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java
Modified:
search/trunk/src/java/org/hibernate/search/FullTextSession.java
search/trunk/src/java/org/hibernate/search/backend/Worker.java
search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java
search/trunk/src/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
search/trunk/src/test/org/hibernate/search/test/session/Email.java
search/trunk/src/test/org/hibernate/search/test/session/MassIndexTest.java
search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java
search/trunk/src/test/org/hibernate/search/test/session/SessionTest.java
Log:
HSEARCH-220 introduce session.flushToIndexes
Modified: search/trunk/src/java/org/hibernate/search/FullTextSession.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/FullTextSession.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/FullTextSession.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -50,4 +50,10 @@
* @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
*/
public void purgeAll(Class entityType);
+
+ /**
+ * flush full text changes to the index
+ * Force Hibernate Search to apply all changes to the index no waiting for the batch limit
+ */
+ public void flushToIndexes();
}
Modified: search/trunk/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -22,4 +22,9 @@
* This method can return exceptions
*/
void close();
+
+ /**
+ * flush any work queue
+ */
+ void flushWorks(EventSource session);
}
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -56,4 +56,10 @@
if (queuePerTransaction != null) queuePerTransaction.removeValue( this );
}
}
+
+ public void flushWorks() {
+ WorkQueue subQueue = queue.splitQueue();
+ queueingProcessor.prepareWorks( subQueue );
+ queueingProcessor.performWorks( subQueue );
+ }
}
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -54,4 +54,15 @@
queueingProcessor.close();
}
+ public void flushWorks(EventSource session) {
+ if ( session.isTransactionInProgress() ) {
+ Transaction transaction = session.getTransaction();
+ PostTransactionWorkQueueSynchronization txSync = (PostTransactionWorkQueueSynchronization)
+ synchronizationPerTransaction.get( transaction );
+ if ( txSync != null && ! txSync.isConsumed() ) {
+ txSync.flushWorks();
+ }
+ }
+ }
+
}
Modified: search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -92,6 +92,11 @@
purge( entityType, null );
}
+ public void flushToIndexes() {
+ SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
+ searchFactoryImplementor.getWorker().flushWorks(eventSource);
+ }
+
/**
* Remove a particular entity from a particular class of an index.
*
Modified: search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/jpa/FullTextEntityManager.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -50,4 +50,10 @@
*/
public void purgeAll(Class entityType);
+ /**
+ * flush index change
+ * Force Hibernate Search to apply all changes to the index no waiting for the batch limit
+ */
+ public void flushToIndexes();
+
}
Modified: search/trunk/src/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -77,7 +77,11 @@
getFullTextSession().purgeAll( entityType );
}
+ public void flushToIndexes() {
+ getFullTextSession().flushToIndexes();
+ }
+
public void persist(Object entity) {
em.persist( entity );
}
Added: search/trunk/src/test/org/hibernate/search/test/session/Domain.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/Domain.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/session/Domain.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -0,0 +1,37 @@
+package org.hibernate.search.test.session;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed
+public class Domain {
+ @Id
+ @DocumentId
+ private Integer id;
+ @Field
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: search/trunk/src/test/org/hibernate/search/test/session/Email.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/Email.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/test/org/hibernate/search/test/session/Email.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -4,11 +4,14 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToOne;
+import javax.persistence.FetchType;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.IndexedEmbedded;
/**
* @author Emmanuel Bernard
@@ -28,7 +31,17 @@
private String header;
+ @IndexedEmbedded @ManyToOne(fetch = FetchType.LAZY)
+ private Domain domain;
+ public Domain getDomain() {
+ return domain;
+ }
+
+ public void setDomain(Domain domain) {
+ this.domain = domain;
+ }
+
public Long getId() {
return id;
}
Modified: search/trunk/src/test/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/MassIndexTest.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/test/org/hibernate/search/test/session/MassIndexTest.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -31,8 +31,10 @@
int loop = 14;
for (int i = 0; i < loop; i++) {
Statement statmt = s.connection().createStatement();
- statmt.executeUpdate( "insert into Email(id, title, body, header) values( + "
- + ( i + 1 ) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')" );
+ statmt.executeUpdate( "insert into Domain(id, name) values( + "
+ + ( i + 1 ) + ", 'sponge" + i + "')" );
+ statmt.executeUpdate( "insert into Email(id, title, body, header, domain_id) values( + "
+ + ( i + 1 ) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope', " + ( i + 1 ) +")" );
statmt.close();
}
tx.commit();
@@ -61,6 +63,7 @@
s.close();
}
+
public void testTransactional() throws Exception {
FullTextSession s = Search.createFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
@@ -192,7 +195,8 @@
return new Class[] {
Email.class,
Entite.class,
- Categorie.class
+ Categorie.class,
+ Domain.class
};
}
}
Added: search/trunk/src/test/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -0,0 +1,74 @@
+package org.hibernate.search.test.session;
+
+import java.sql.Statement;
+import java.util.List;
+
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.Environment;
+import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.impl.FullTextSessionImpl;
+import org.hibernate.Transaction;
+import org.hibernate.ScrollableResults;
+import org.hibernate.ScrollMode;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.analysis.StopAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MassIndexUsingManualFlushTest extends SearchTestCase {
+ public void testManualIndexFlush() throws Exception {
+ FullTextSession s = Search.createFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ int loop = 14;
+ for (int i = 0; i < loop; i++) {
+ Statement statmt = s.connection().createStatement();
+ statmt.executeUpdate( "insert into Domain(id, name) values( + "
+ + ( i + 1 ) + ", 'sponge" + i + "')" );
+ statmt.executeUpdate( "insert into Email(id, title, body, header, domain_id) values( + "
+ + ( i + 1 ) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope', " + ( i + 1 ) +")" );
+ statmt.close();
+ }
+ tx.commit();
+ s.close();
+
+ //check non created object does get found!!1
+ s = new FullTextSessionImpl( openSession() );
+ tx = s.beginTransaction();
+ ScrollableResults results = s.createCriteria( Email.class ).scroll( ScrollMode.FORWARD_ONLY );
+ int index = 0;
+ while ( results.next() ) {
+ index++;
+ final Email o = (Email) results.get( 0 );
+ s.index( o );
+ if ( index % 5 == 0 ) {
+ s.flushToIndexes();
+ s.clear();
+ }
+ }
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "id", new StopAnalyzer() );
+ List result = s.createFullTextQuery( parser.parse( "body:create" ) ).list();
+ assertEquals( 14, result.size() );
+ for (Object object : result) {
+ s.delete( object );
+ }
+ tx.commit();
+ s.close();
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Email.class,
+ Domain.class
+ };
+ }
+}
Modified: search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -84,7 +84,8 @@
protected Class[] getMappings() {
return new Class[] {
- Email.class
+ Email.class,
+ Domain.class
};
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/session/SessionTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/SessionTest.java 2008-06-20 22:27:08 UTC (rev 14793)
+++ search/trunk/src/test/org/hibernate/search/test/session/SessionTest.java 2008-06-21 13:47:31 UTC (rev 14794)
@@ -32,7 +32,7 @@
wrapper
);
try {
- FullTextSession fts = Search.createFullTextSession( wrapped );
+ Search.createFullTextSession( wrapped );
}
catch( ClassCastException e ) {
e.printStackTrace( );
@@ -57,7 +57,8 @@
protected Class[] getMappings() {
return new Class[] {
- Email.class
+ Email.class,
+ Domain.class
};
}
}
16 years, 5 months
Hibernate SVN: r14792 - core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/jdbc.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2008-06-20 13:47:48 -0400 (Fri, 20 Jun 2008)
New Revision: 14792
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/jdbc/AbstractBatcher.java
Log:
HHH-3006 : occasional infinite loop on JTA tx-timeout
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/jdbc/AbstractBatcher.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/jdbc/AbstractBatcher.java 2008-06-20 17:42:09 UTC (rev 14791)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/jdbc/AbstractBatcher.java 2008-06-20 17:47:48 UTC (rev 14792)
@@ -8,6 +8,7 @@
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.ConcurrentModificationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -298,40 +299,62 @@
releasing = true;
try {
- if (batchUpdate!=null) batchUpdate.close();
+ if ( batchUpdate != null ) {
+ batchUpdate.close();
+ }
}
- catch (SQLException sqle) {
+ catch ( SQLException sqle ) {
//no big deal
- log.warn("Could not close a JDBC prepared statement", sqle);
+ log.warn( "Could not close a JDBC prepared statement", sqle );
}
- batchUpdate=null;
- batchUpdateSQL=null;
+ batchUpdate = null;
+ batchUpdateSQL = null;
Iterator iter = resultSetsToClose.iterator();
while ( iter.hasNext() ) {
try {
logCloseResults();
- ( (ResultSet) iter.next() ).close();
+ ( ( ResultSet ) iter.next() ).close();
}
- catch (SQLException e) {
+ catch ( SQLException e ) {
// no big deal
- log.warn("Could not close a JDBC result set", e);
+ log.warn( "Could not close a JDBC result set", e );
}
- catch (Throwable e) {
- // sybase driver (jConnect) throwing NPE here in certain cases
- log.warn("Could not close a JDBC result set", e);
+ catch ( ConcurrentModificationException e ) {
+ // this has been shown to happen occasionally in rare cases
+ // when using a transaction manager + transaction-timeout
+ // where the timeout calls back through Hibernate's
+ // registered transaction synchronization on a separate
+ // "reaping" thread. In cases where that reaping thread
+ // executes through this block at the same time the main
+ // application thread does we can get into situations where
+ // these CMEs occur. And though it is not "allowed" per-se,
+ // the end result without handling it specifically is infinite
+ // looping. So here, we simply break the loop
+ log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
+ break;
}
+ catch ( Throwable e ) {
+ // sybase driver (jConnect) throwing NPE here in certain
+ // cases, but we'll just handle the general "unexpected" case
+ log.warn( "Could not close a JDBC result set", e );
+ }
}
resultSetsToClose.clear();
iter = statementsToClose.iterator();
while ( iter.hasNext() ) {
try {
- closeQueryStatement( (PreparedStatement) iter.next() );
+ closeQueryStatement( ( PreparedStatement ) iter.next() );
}
- catch (SQLException e) {
+ catch ( ConcurrentModificationException e ) {
+ // see explanation above...
+ log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
+ break;
+ }
+ catch ( SQLException e ) {
// no big deal
- log.warn("Could not close a JDBC statement", e);
+ log.warn( "Could not close a JDBC statement", e );
}
}
statementsToClose.clear();
16 years, 5 months