Hibernate SVN: r19975 - in search/branches/Branch_3_2: hibernate-search and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:16:13 -0400 (Tue, 20 Jul 2010)
New Revision: 19975
Modified:
search/branches/Branch_3_2/hibernate-search-archetype/pom.xml
search/branches/Branch_3_2/hibernate-search-testing/pom.xml
search/branches/Branch_3_2/hibernate-search/pom.xml
search/branches/Branch_3_2/hibernate-search/src/main/docbook/en-US/modules/getting-started.xml
search/branches/Branch_3_2/pom.xml
Log:
Upgrade version number to 3.2.1-SNAPSHOT
Modified: search/branches/Branch_3_2/hibernate-search/pom.xml
===================================================================
--- search/branches/Branch_3_2/hibernate-search/pom.xml 2010-07-20 09:15:34 UTC (rev 19974)
+++ search/branches/Branch_3_2/hibernate-search/pom.xml 2010-07-20 09:16:13 UTC (rev 19975)
@@ -28,7 +28,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.2.0.Final</version>
+ <version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Modified: search/branches/Branch_3_2/hibernate-search/src/main/docbook/en-US/modules/getting-started.xml
===================================================================
--- search/branches/Branch_3_2/hibernate-search/src/main/docbook/en-US/modules/getting-started.xml 2010-07-20 09:15:34 UTC (rev 19974)
+++ search/branches/Branch_3_2/hibernate-search/src/main/docbook/en-US/modules/getting-started.xml 2010-07-20 09:16:13 UTC (rev 19975)
@@ -25,7 +25,7 @@
-->
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
-<!ENTITY version "3.2.0.Final">
+<!ENTITY version "3.2.1.Final">
]>
<chapter id="getting-started">
<title>Getting started</title>
Modified: search/branches/Branch_3_2/hibernate-search-archetype/pom.xml
===================================================================
--- search/branches/Branch_3_2/hibernate-search-archetype/pom.xml 2010-07-20 09:15:34 UTC (rev 19974)
+++ search/branches/Branch_3_2/hibernate-search-archetype/pom.xml 2010-07-20 09:16:13 UTC (rev 19975)
@@ -10,7 +10,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.2.0.Final</version>
+ <version>3.2.1-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
Modified: search/branches/Branch_3_2/hibernate-search-testing/pom.xml
===================================================================
--- search/branches/Branch_3_2/hibernate-search-testing/pom.xml 2010-07-20 09:15:34 UTC (rev 19974)
+++ search/branches/Branch_3_2/hibernate-search-testing/pom.xml 2010-07-20 09:16:13 UTC (rev 19975)
@@ -28,7 +28,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.2.0.Final</version>
+ <version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Modified: search/branches/Branch_3_2/pom.xml
===================================================================
--- search/branches/Branch_3_2/pom.xml 2010-07-20 09:15:34 UTC (rev 19974)
+++ search/branches/Branch_3_2/pom.xml 2010-07-20 09:16:13 UTC (rev 19975)
@@ -27,7 +27,7 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-parent</artifactId>
- <version>3.2.0.Final</version>
+ <version>3.2.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Hibernate Search Aggregator</name>
14 years, 4 months
Hibernate SVN: r19974 - search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:15:34 -0400 (Tue, 20 Jul 2010)
New Revision: 19974
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
Log:
HSEARCH-540 let the queue unsealed to cope with double preparation risk
Due to the flush process being called potentially after the queue processing
and thus the double queue processing registration, we:
- no longer seal the queue
- no longer clear the queue
So that the second processing can reprocess the works
Modified: search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20 09:15:01 UTC (rev 19973)
+++ search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20 09:15:34 UTC (rev 19974)
@@ -24,24 +24,26 @@
*/
package org.hibernate.search.backend;
+import java.util.ArrayList;
import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
+import org.slf4j.Logger;
+
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.search.util.LoggerFactory;
-import org.slf4j.Logger;
/**
* @author Emmanuel Bernard
*/
public class WorkQueue {
-
+
private static final Logger log = LoggerFactory.make();
-
+
private List<Work> queue;
private List<LuceneWork> sealedQueue;
+ //is this class supposed to be
+ private boolean usedSealedData;
public WorkQueue(int size) {
queue = new ArrayList<Work>(size);
@@ -56,6 +58,10 @@
}
public void add(Work work) {
+ if ( usedSealedData ) {
+ //something is wrong fail with exception
+ throw new AssertionFailure( "Attempting to add a work in a used sealed queue" );
+ }
queue.add(work);
}
@@ -71,12 +77,22 @@
public List<LuceneWork> getSealedQueue() {
if (sealedQueue == null) throw new AssertionFailure("Access a Sealed WorkQueue which has not been sealed");
+ usedSealedData = true;
return sealedQueue;
}
public void setSealedQueue(List<LuceneWork> sealedQueue) {
//invalidate the working queue for serializability
- queue = Collections.EMPTY_LIST;
+ /*
+ * FIXME workaround for flush phase done later
+ *
+ * Due to sometimes flush applied after some beforeCompletion phase
+ * we cannot safely seal the queue, keep it opened as a temporary measure.
+ * This is not the proper fix unfortunately as we don't optimize the whole work queue but rather two subsets
+ *
+ * when the flush ordering is fixed, add the following line
+ * queue = Collections.EMPTY_LIST;
+ */
this.sealedQueue = sealedQueue;
}
14 years, 4 months
Hibernate SVN: r19973 - search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:15:01 -0400 (Tue, 20 Jul 2010)
New Revision: 19973
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
Log:
Add trace on transaction before / after completion phases
Modified: search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-07-20 09:14:26 UTC (rev 19972)
+++ search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-07-20 09:15:01 UTC (rev 19973)
@@ -74,9 +74,14 @@
public void beforeCompletion() {
if ( prepared ) {
- log.trace("This transaction has already been processed, ignoring beforeCompletion()");
+ if ( log.isTraceEnabled() ) {
+ log.trace("Transaction's beforeCompletion() phase already been processed, ignoring: {}", this.toString() );
+ }
}
else {
+ if ( log.isTraceEnabled() ) {
+ log.trace("Processing Transaction's beforeCompletion() phase: {}", this.toString() );
+ }
queueingProcessor.prepareWorks(queue);
prepared = true;
}
@@ -85,9 +90,15 @@
public void afterCompletion(int i) {
try {
if ( Status.STATUS_COMMITTED == i ) {
+ if ( log.isTraceEnabled() ) {
+ log.trace("Processing Transaction's afterCompletion() phase for {}. Performing work.", this.toString() );
+ }
queueingProcessor.performWorks(queue);
}
else {
+ if ( log.isTraceEnabled() ) {
+ log.trace("Processing Transaction's afterCompletion() phase for {}. Cancelling work due to transaction status {}", this.toString(), i );
+ }
queueingProcessor.cancelWorks(queue);
}
}
14 years, 4 months
Hibernate SVN: r19972 - search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:14:26 -0400 (Tue, 20 Jul 2010)
New Revision: 19972
Modified:
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java
search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
Log:
HSEARCH-540 register both JTA Synchronization and action's registerProcess
This circumvent a bug in Core see email on the mailing list hibernate-dev
"Re: [hibernate-dev] Exceptions thrown in a tx synchronization are eaten"
The before tx completion process is called before tx synchronizations, and in JTA the auto-flush at the end of a session is done using a TX synchronization
Modified: search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java
===================================================================
--- search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java 2010-07-20 09:05:09 UTC (rev 19971)
+++ search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java 2010-07-20 09:14:26 UTC (rev 19972)
@@ -82,10 +82,25 @@
if ( isRealTransactionInProgress() ) {
//use {Before|After}TransactionCompletionProcess instead of registerTransaction because it does not
//swallow transactions.
+ /*
+ * HSEARCH-540: the pre process must be both a BeforeTransactionCompletionProcess and a TX Synchronization.
+ *
+ * In a resource-local tx env, the beforeCommit phase is called after the flush, and prepares work queue.
+ * Also, any exceptions that occur during that are propagated (if a Synchronization was used, the exceptions
+ * would be eaten).
+ *
+ * In a JTA env, the before transaction completion is called before the flush, so not all changes are yet
+ * written. However, Synchronization-s do propagate exceptions, so they can be safely used.
+ */
+
final ActionQueue actionQueue = eventSource.getActionQueue();
actionQueue.registerProcess( new DelegateToSynchronizationOnBeforeTx( synchronization ) );
+ eventSource.getTransaction().registerSynchronization(
+ new BeforeCommitSynchronizationDelegator( synchronization )
+ );
+
+ //executed in all environments
actionQueue.registerProcess( new DelegateToSynchronizationOnAfterTx( synchronization ) );
-// eventSource.getTransaction().registerSynchronization( synchronization );
}
else {
//registerSynchronization is only called if isRealTransactionInProgress or if
@@ -165,5 +180,21 @@
}
}
}
+
+ private static class BeforeCommitSynchronizationDelegator implements Synchronization {
+ private final Synchronization synchronization;
+
+ public BeforeCommitSynchronizationDelegator(Synchronization sync) {
+ this.synchronization = sync;
+ }
+
+ public void beforeCompletion() {
+ this.synchronization.beforeCompletion();
+ }
+
+ public void afterCompletion(int status) {
+ //do not delegate
+ }
+ }
}
Modified: search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-07-20 09:05:09 UTC (rev 19971)
+++ search/branches/Branch_3_2/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-07-20 09:14:26 UTC (rev 19972)
@@ -27,9 +27,12 @@
import javax.transaction.Status;
import javax.transaction.Synchronization;
+import org.slf4j.Logger;
+
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.util.LoggerFactory;
import org.hibernate.search.util.WeakIdentityHashMap;
/**
@@ -38,6 +41,8 @@
* @author Emmanuel Bernard
*/
public class PostTransactionWorkQueueSynchronization implements Synchronization {
+
+ private static final Logger log = LoggerFactory.make();
/**
* FullTextIndexEventListener is using a WeakIdentityHashMap<Session,Synchronization>
@@ -47,6 +52,7 @@
private final QueueingProcessor queueingProcessor;
private boolean consumed;
+ private boolean prepared;
private final WeakIdentityHashMap queuePerTransaction;
private WorkQueue queue = new WorkQueue();
@@ -67,7 +73,13 @@
}
public void beforeCompletion() {
- queueingProcessor.prepareWorks(queue);
+ if ( prepared ) {
+ log.trace("This transaction has already been processed, ignoring beforeCompletion()");
+ }
+ else {
+ queueingProcessor.prepareWorks(queue);
+ prepared = true;
+ }
}
public void afterCompletion(int i) {
14 years, 4 months
Hibernate SVN: r19971 - in search/trunk: hibernate-search-integrationtest and 10 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:05:09 -0400 (Tue, 20 Jul 2010)
New Revision: 19971
Added:
search/trunk/hibernate-search-integrationtest/
search/trunk/hibernate-search-integrationtest/pom.xml
search/trunk/hibernate-search-integrationtest/src/
search/trunk/hibernate-search-integrationtest/src/test/
search/trunk/hibernate-search-integrationtest/src/test/java/
search/trunk/hibernate-search-integrationtest/src/test/java/org/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java
search/trunk/hibernate-search-integrationtest/src/test/resources/
search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml
search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
Modified:
search/trunk/pom.xml
Log:
HSEARCH-561 Add integration test module
It contains a test using both Spring Framework and a JTA transaction manager.
TODO: convert Bitronix to JBossTS
Added: search/trunk/hibernate-search-integrationtest/pom.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/pom.xml (rev 0)
+++ search/trunk/hibernate-search-integrationtest/pom.xml 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ 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>
+
+ <parent>
+ <artifactId>hibernate-search-parent</artifactId>
+ <groupId>org.hibernate</groupId>
+ <version>3.3.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>hibernate-search-integrationtest</artifactId>
+
+ <name>Hibernate Search integration test</name>
+ <description>Hibernate Search integration tests. In particular with Spring Framework and JTA</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring-release-version>3.0.2.RELEASE</spring-release-version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+ <dependencies>
+
+ <!-- Hibernate -->
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-search</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${hibernateVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.12.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <!-- override version for annotation based JUnit -->
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Spring Framework -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- JSR 330 - @Inject annotation -->
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Bitronix Transaction Manager -->
+ <dependency>
+ <groupId>org.codehaus.btm</groupId>
+ <artifactId>btm</artifactId>
+ <version>2.0.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.139</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
\ No newline at end of file
Property changes on: search/trunk/hibernate-search-integrationtest/pom.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,37 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+
+import org.hibernate.annotations.NaturalId;
+
+@MappedSuperclass
+public abstract class AbstractEntity {
+
+ @NaturalId(mutable=true)
+ @Column(length=36)
+ private String magicKey_;
+
+ /**
+ * Sets the magic key for the instance
+ */
+ public AbstractEntity() {
+ magicKey_ = UUID.randomUUID().toString();
+ }
+
+ /**
+ * @return the magicKey
+ */
+ public String getMagicKey() {
+ return magicKey_;
+ }
+
+ /**
+ * @param magicKey the magicKey to set
+ */
+ public void setMagicKey(String magicKey) {
+ magicKey_ = magicKey;
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,81 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.ForeignKey;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+@Entity
+@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region="container")
+
+@Indexed(index="container")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Box extends Container {
+ @OneToMany(mappedBy="box", cascade={ CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.PERSIST }, fetch=FetchType.LAZY)
+ @ForeignKey(name="FK_Box_Muffins")
+ private Set<Muffin> muffinSet;
+
+ @OneToMany(mappedBy="box", cascade={ CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.PERSIST }, fetch=FetchType.LAZY)
+ @ForeignKey(name="FK_Box_Doughnuts")
+ private Set<Doughnut> doughnutSet;
+
+ public Box() {
+ }
+
+ /**
+ * @return the color
+ */
+ public void addMuffin(Muffin muffin) {
+ if (muffinSet == null) {
+ muffinSet = new HashSet<Muffin>();
+ }
+
+ muffinSet.add(muffin);
+ }
+
+ /**
+ * @return the muffinSet
+ */
+ public Set<Muffin> getMuffinSet() {
+ return muffinSet;
+ }
+
+ /**
+ * @param muffinSet the muffinSet to set
+ */
+ public void setMuffinSet(Set<Muffin> muffinSet) {
+ this.muffinSet = muffinSet;
+ }
+
+ /**
+ * @return the doughnutSet
+ */
+ public Set<Doughnut> getDoughnutSet() {
+ return doughnutSet;
+ }
+
+ /**
+ * @param doughnutSet the doughnutSet to set
+ */
+ public void setDoughnutSet(Set<Doughnut> doughnutSet) {
+ this.doughnutSet = doughnutSet;
+ }
+
+ public void addDoughnut(Doughnut doughnut) {
+ if (doughnutSet == null) {
+ doughnutSet = new HashSet<Doughnut>();
+ }
+
+ doughnutSet.add(doughnut);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,38 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class BoxDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Box box) {
+ entityManager.persist(box);
+// entityManager.flush();
+ }
+
+ @Transactional
+ public Box merge(Box box) {
+ Box result = entityManager.merge(box);
+
+// entityManager.flush();
+
+ return result;
+ }
+
+ @Transactional
+ public void remove(Box box) {
+ entityManager.remove(box);
+// entityManager.flush();
+ }
+
+ public EntityManager getEntityManager() {
+ return entityManager;
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BoxRun {
+ private ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:beans.xml");
+
+ public void run() {
+ BoxDAO boxDAO = (BoxDAO) applicationContext.getBean("boxDAO");
+
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Muffin muffin = new Muffin();
+ muffin.setKind("blueberry");
+ muffin.setBox(box);
+
+ box.addMuffin(muffin);
+
+ boxDAO.merge(box);
+ }
+
+ public static void main(String args[]) {
+ new BoxRun().run();
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,61 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+@Entity
+(a)Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+@Table(name="container")
+@DiscriminatorColumn(name = "containerType", discriminatorType = DiscriminatorType.STRING)
+
+@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region="container")
+
+@Indexed(index="container")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Container extends AbstractEntity {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long containerId;
+
+ @Column(length = 255)
+ private String color;
+
+ /**
+ * @return the containerId
+ */
+ public Long getContainerId() {
+ return containerId;
+ }
+
+ /**
+ * @param containerId the containerId to set
+ */
+ public void setContainerId(Long containerId) {
+ this.containerId = containerId;
+ }
+
+ public String getColor() {
+ return color;
+ }
+
+ /**
+ * @param color the color to set
+ */
+ public void setColor(String color) {
+ this.color = color;
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,77 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+//Hibernate
+@Entity
+@Table(name = "doughnut")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="doughnut")
+// Hibernate Search
+@Indexed(index="Doughnut")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Doughnut {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long doughnutId;
+
+ @ManyToOne
+ private Box box;
+
+ @Column(length = 255,nullable=false)
+ private String kind;
+
+ /**
+ * @return the doughnutId
+ */
+ public Long getDoughnutId() {
+ return doughnutId;
+ }
+
+ /**
+ * @param doughnutId the doughnutId to set
+ */
+ public void setDoughnutId(Long doughnutId) {
+ this.doughnutId = doughnutId;
+ }
+
+ /**
+ * @return the box
+ */
+ public Box getBox() {
+ return box;
+ }
+
+ /**
+ * @param box the box to set
+ */
+ public void setBox(Box box) {
+ this.box = box;
+ }
+
+ /**
+ * @return the kind
+ */
+ public String getKind() {
+ return kind;
+ }
+
+ /**
+ * @param kind the kind to set
+ */
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,47 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"classpath*:beans.xml"})
+//@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
+//@Transactional
+public class JtaAndSpringMoreComplexTest {
+ @Inject
+ private BoxDAO boxDAO;
+
+ @Test
+ public void testMufins() throws Exception {
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Muffin muffin = new Muffin();
+ muffin.setKind("blueberry");
+ muffin.setBox(box);
+
+ box.addMuffin(muffin);
+
+ boxDAO.merge(box);
+ }
+
+ @Test
+ public void testDoughnuts() throws Exception {
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Doughnut doughnut = new Doughnut();
+ doughnut.setKind("glazed");
+ doughnut.setBox(box);
+
+ box.addDoughnut(doughnut);
+
+ boxDAO.merge(box);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,31 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+import org.springframework.transaction.annotation.Transactional;
+
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"classpath*:beans.xml"})
+@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
+@Transactional
+public class JtaAndSpringTest {
+ @Inject
+ private SnertDAO snertDAO;
+
+ @Test
+ public void test() {
+ Snert snert = new Snert();
+
+ snert.setName("dave");
+ snert.setNickname("dude");
+ snert.setAge(99);
+ snert.setCool(Boolean.TRUE);
+
+ snertDAO.persist(snert);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,78 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+// Hibernate
+@Entity
+@Table(name = "muffin")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="muffin")
+// Hibernate Search
+//@Indexed(index="Muffin")
+//@Analyzer(impl = StandardAnalyzer.class)
+public class Muffin {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long muffinId;
+
+ @ManyToOne
+ private Box box;
+
+ @Column(length = 255,nullable=false)
+ private String kind;
+
+ public Muffin() {
+ }
+
+ /**
+ * @return the muffinId
+ */
+ public Long getMuffinId() {
+ return muffinId;
+ }
+
+ /**
+ * @param muffinId the muffinId to set
+ */
+ public void setMuffinId(Long muffinId) {
+ this.muffinId = muffinId;
+ }
+
+ /**
+ * @return the box
+ */
+ public Box getBox() {
+ return box;
+ }
+
+ /**
+ * @param box the box to set
+ */
+ public void setBox(Box box) {
+ this.box = box;
+ }
+
+ /**
+ * @return the kind
+ */
+ public String getKind() {
+ return kind;
+ }
+
+ /**
+ * @param kind the kind to set
+ */
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class MuffinDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Muffin muffin) {
+ entityManager.persist(muffin);
+ }
+
+ @Transactional
+ public void merge(Muffin muffin) {
+ entityManager.merge(muffin);
+ }
+
+ @Transactional
+ public void remove(Muffin muffin) {
+ entityManager.remove(muffin);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,143 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.TermVector;
+
+@Entity
+@Table(name = "snert")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="snert")
+
+// full text search
+@Indexed(index="Snert")
+@Analyzer(impl = StandardAnalyzer.class)
+
+public class Snert {
+
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @DocumentId
+ private Long id;
+
+ @Column(nullable=true)
+ private Date birthday;
+
+ @Column(length = 255)
+ @Field(index = Index.TOKENIZED, store = Store.NO, termVector = TermVector.YES)
+ private String name;
+
+ @Column(length=24)
+ private String nickname;
+
+ @Field(index=Index.UN_TOKENIZED, store=Store.NO)
+ private Boolean cool;
+
+ @Column(name="readCount")
+ @Field(index=Index.UN_TOKENIZED, store=Store.YES)
+ private int age;
+
+ public Snert() {
+ }
+
+ /**
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the birthday
+ */
+ public Date getBirthday() {
+ return birthday;
+ }
+
+ /**
+ * @param birthday the birthday to set
+ */
+ public void setBirthday(Date birthday) {
+ this.birthday = birthday;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the nickname
+ */
+ public String getNickname() {
+ return nickname;
+ }
+
+ /**
+ * @param nickname the nickname to set
+ */
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ /**
+ * @return the cool
+ */
+ public Boolean getCool() {
+ return cool;
+ }
+
+ /**
+ * @param cool the cool to set
+ */
+ public void setCool(Boolean cool) {
+ this.cool = cool;
+ }
+
+ /**
+ * @return the age
+ */
+ public int getAge() {
+ return age;
+ }
+
+ /**
+ * @param age the age to set
+ */
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class SnertDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Snert snert) {
+ entityManager.persist(snert);
+ }
+
+ @Transactional
+ public void merge(Snert snert) {
+ entityManager.merge(snert);
+ }
+
+ @Transactional
+ public void remove(Snert snert) {
+ entityManager.remove(snert);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
+ <property name="className" value="org.h2.jdbcx.JdbcDataSource" />
+ <property name="uniqueName" value="xaDataSource" />
+ <property name="allowLocalTransactions" value="true"/>
+ <property name="minPoolSize" value="5" />
+ <property name="maxPoolSize" value="100" />
+ <property name="maxIdleTime" value="100" />
+ <property name="testQuery" value="select 1+1 as sum" />
+ <property name="driverProperties">
+ <props>
+ <prop key="URL">jdbc:h2:mem:foobar</prop>
+ <!-- <prop key="user">root</prop>
+ <prop key="password"></prop> -->
+ </props>
+ </property>
+ </bean>
+
+ <!--
+ Process @PersistenceContext to inject entity manager factory
+ -->
+ <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
+
+ <!--
+ process @Transactional to create transaction proxies
+ -->
+ <tx:annotation-driven transaction-manager="transactionManager" />
+
+ <context:component-scan base-package="org.hibernate.search.test.integration.jtaspring"/>
+
+ <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="database" value="H2" />
+ <property name="showSql" value="false" />
+ <property name="generateDdl" value="false" />
+ </bean>
+
+ <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
+ depends-on="btmConfig">
+ <property name="loadTimeWeaver">
+ <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
+ </property>
+ <property name="persistenceUnitName" value="integration" />
+ <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
+
+ <property name="dataSource" ref="dataSource" />
+ <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
+
+ <property name="jpaPropertyMap">
+ <map>
+ <entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
+ <entry key="hibernate.hbm2ddl.auto" value="create-drop" />
+ <entry key="hibernate.jdbc.batch_size" value="400" />
+ <entry key="hibernate.jdbc.fetch_size" value="200" />
+ <entry key="hibernate.jdbc.wrap_result_sets" value="true" />
+ <entry key="hibernate.generate_statistics" value="true" />
+ <!-- 2 is TRANSACTION_READ_COMMITTED -->
+ <entry key="hibernate.connection.isolation" value="2" />
+ <!-- http://docs.jboss.org/hibernate/core/3.3/reference/en/html/architecture.h... -->
+ <entry key="hibernate.current_session_context_class" value="org.hibernate.context.JTASessionContext" />
+
+ <!-- trying things to make Oracle happy -->
+ <entry key="hibernate.jdbc.batch_size" value="0" />
+
+ <!-- second level cache config for all cache providers -->
+ <entry key="hibernate.cache.use_second_level_cache" value="false" />
+ <entry key="hibernate.cache.use_query_cache" value="false" />
+ <entry key="hibernate.cache.region_prefix" value="integration" />
+
+ <!-- second level cache - Infinispan -->
+ <!-- <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory" /> -->
+ <!-- With statistics on transaction would not commit -->
+ <!-- <entry key="hibernate.cache.infinispan.statistics" value="true"/> -->
+
+ <!-- Atomikos JTA for Hibernate, required to get this JPA provider involved in JTA -->
+ <!-- no value should be setup for hibernate.transaction.factory_class, it is not required -->
+ <entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
+
+ <!-- Hibernate Search -->
+ <entry key="hibernate.search.default.indexBase" value="." />
+ <entry key="hibernate.search.default.directory_provider" value="org.hibernate.search.store.RAMDirectoryProvider" />
+ <entry key="hibernate.search.worker.execution" value="async" />
+ <entry key="hibernate.search.default.optimizer.transaction_limit.max" value="100" />
+ <entry key="hibernate.search.worker.thread_pool.size" value="1" />
+ <entry key="hibernate.search.worker.buffer_queue.max" value="1000000" />
+
+ </map>
+ </property>
+ </bean>
+
+ <!-- From http://docs.codehaus.org/display/BTM/Spring+Framework13 -->
+ <!-- Bitronix Transaction Manager embedded configuration -->
+ <bean id="btmConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
+ <!-- property serverId should not be set when BTMTransactionManagerLookup is configured as the
+ hibernate transaction manager lookup class -->
+ <!-- <property name="serverId" value="spring-btm" /> -->
+ <property name="journal" value="null"/>
+ </bean>
+
+ <!-- create BTM transaction manager -->
+ <bean id="BitronixTransactionManager" factory-method="getTransactionManager"
+ class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig,dataSource" destroy-method="shutdown" />
+
+ <!-- Spring JtaTransactionManager -->
+ <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
+ <property name="transactionManager" ref="BitronixTransactionManager" />
+ <property name="userTransaction" ref="BitronixTransactionManager" />
+ </bean>
+
+ <!-- Atomikos Transactions -->
+ <!-- http://www.atomikos.com/Documentation/SpringIntegration#The_Advanced_Case... -->
+
+<!-- <bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce">
+ <constructor-arg> -->
+ <!-- IMPORTANT: specify all Atomikos properties here (in constructor args) -->
+<!-- <props>
+ <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
+ <prop key="com.atomikos.icatch.automatic_resource_registration">false</prop>
+ <prop key="com.atomikos.icatch.console_log_level">WARN</prop>
+ <prop key="com.atomikos.icatch.force_shutdown_on_vm_exit">true</prop>
+ <prop key="com.atomikos.icatch.enable_logging">false</prop>
+ <prop key="com.atomikos.icatch.serial_jta_transactions">false</prop>
+ </props>
+ </constructor-arg>
+ </bean> -->
+
+ <!-- when close is called, should we force transactions to terminate or not? -->
+<!-- <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" depends-on="userTransactionService">
+ <property name="forceShutdown" value="false" />
+ </bean> -->
+
+ <!-- Also use Atomikos UserTransactionImp, needed to configure Spring -->
+<!-- <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService">
+ <property name="transactionTimeout" value="300" />
+ </bean> -->
+
+ <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
+<!-- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService">
+ <property name="transactionManager" ref="atomikosTransactionManager" />
+ <property name="userTransaction" ref="atomikosUserTransaction" />
+ </bean> -->
+
+ <!-- Spring JPA Transaction Manager, 1PC -->
+ <!-- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
+ </bean> -->
+
+
+</beans>
+
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,8 @@
+log4j.rootCategory=INFO, CONSOLE
+
+# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n
+
+#log4j.logger.org.hibernate.search=TRACE
\ No newline at end of file
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml (rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml 2010-07-20 09:05:09 UTC (rev 19971)
@@ -0,0 +1,10 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="integration" transaction-type="JTA">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <class>org.hibernate.search.test.integration.jtaspring.Snert</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Container</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Box</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Doughnut</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Muffin</class>
+ </persistence-unit>
+</persistence>
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-07-20 09:03:29 UTC (rev 19970)
+++ search/trunk/pom.xml 2010-07-20 09:05:09 UTC (rev 19971)
@@ -42,6 +42,7 @@
<module>hibernate-search</module>
<module>hibernate-search-testing</module>
<module>hibernate-search-archetype</module>
+ <module>hibernate-search-integrationtest</module>
</modules>
<issueManagement>
14 years, 4 months
Hibernate SVN: r19970 - in search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend: impl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-20 05:03:29 -0400 (Tue, 20 Jul 2010)
New Revision: 19970
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
Log:
HSEARCH-540 Avoid performing the queue twice when nothing has changed
The double registration leads to double processing of the queue which can be avoided by a flag.
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20 01:22:12 UTC (rev 19969)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkQueue.java 2010-07-20 09:03:29 UTC (rev 19970)
@@ -42,8 +42,10 @@
private List<Work> queue;
private List<LuceneWork> sealedQueue;
- //is this class supposed to be
+ //flag indicating if the sealed data has be provided meaning that it should no longer be modified
private boolean usedSealedData;
+ //flag indicating if data has been sealed and not modified since
+ private boolean sealedAndUnchanged;
public WorkQueue(int size) {
queue = new ArrayList<Work>(size);
@@ -53,6 +55,10 @@
this.queue = queue;
}
+ public boolean isSealedAndUnchanged() {
+ return sealedAndUnchanged;
+ }
+
public WorkQueue() {
this(10);
}
@@ -62,6 +68,7 @@
//something is wrong fail with exception
throw new AssertionFailure( "Attempting to add a work in a used sealed queue" );
}
+ this.sealedAndUnchanged = false;
queue.add(work);
}
@@ -72,12 +79,13 @@
public WorkQueue splitQueue() {
WorkQueue subQueue = new WorkQueue( queue );
this.queue = new ArrayList<Work>( queue.size() );
+ this.sealedAndUnchanged = false;
return subQueue;
}
public List<LuceneWork> getSealedQueue() {
if (sealedQueue == null) throw new AssertionFailure("Access a Sealed WorkQueue which has not been sealed");
- usedSealedData = true;
+ this.sealedAndUnchanged = false;
return sealedQueue;
}
@@ -93,11 +101,13 @@
* when the flush ordering is fixed, add the following line
* queue = Collections.EMPTY_LIST;
*/
+ this.sealedAndUnchanged = true;
this.sealedQueue = sealedQueue;
}
public void clear() {
queue.clear();
+ this.sealedAndUnchanged = false;
if (sealedQueue != null) sealedQueue.clear();
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2010-07-20 01:22:12 UTC (rev 19969)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2010-07-20 09:03:29 UTC (rev 19970)
@@ -136,19 +136,22 @@
}
public void prepareWorks(WorkQueue workQueue) {
- List<Work> queue = workQueue.getQueue();
- int initialSize = queue.size();
- List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize ); //TODO load factor for containedIn
- /**
- * Collection work type are process second, so if the owner entity has already been processed for whatever reason
- * the work will be ignored.
- * However if the owner entity has not been processed, an "UPDATE" work is executed
- *
- * Processing collection works last is mandatory to avoid reindexing a object to be deleted
- */
- processWorkByLayer( queue, initialSize, luceneQueue, Layer.FIRST );
- processWorkByLayer( queue, initialSize, luceneQueue, Layer.SECOND );
- workQueue.setSealedQueue( optimize( luceneQueue ) );
+ final boolean alreadyProcessedAndUnchanged = workQueue.isSealedAndUnchanged();
+ if ( !alreadyProcessedAndUnchanged ) {
+ List<Work> queue = workQueue.getQueue();
+ int initialSize = queue.size();
+ List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize ); //TODO load factor for containedIn
+ /**
+ * Collection work type are process second, so if the owner entity has already been processed for whatever reason
+ * the work will be ignored.
+ * However if the owner entity has not been processed, an "UPDATE" work is executed
+ *
+ * Processing collection works last is mandatory to avoid reindexing a object to be deleted
+ */
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.FIRST );
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.SECOND );
+ workQueue.setSealedQueue( optimize( luceneQueue ) );
+ }
}
private List<LuceneWork> optimize(List<LuceneWork> luceneQueue) {
14 years, 4 months
Hibernate SVN: r19969 - in core/trunk: testsuite/src/test/java/org/hibernate/test/cascade and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-07-19 21:22:12 -0400 (Mon, 19 Jul 2010)
New Revision: 19969
Modified:
core/trunk/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java
core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java
Log:
HHH-2269 : Many-to-one cascade fails with TransientObjectException if inverse collection is CascadeType.DELETE_ORPHAN
Modified: core/trunk/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java 2010-07-20 01:04:51 UTC (rev 19968)
+++ core/trunk/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java 2010-07-20 01:22:12 UTC (rev 19969)
@@ -36,14 +36,17 @@
import org.hibernate.HibernateException;
import org.hibernate.LazyInitializationException;
import org.hibernate.engine.CollectionEntry;
+import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.ForeignKeys;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.Status;
import org.hibernate.engine.TypedValue;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.EmptyIterator;
+import org.hibernate.util.IdentitySet;
import org.hibernate.util.MarkerObject;
/**
@@ -905,20 +908,29 @@
// collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
java.util.Set currentIds = new HashSet();
+ java.util.Set currentSaving = new IdentitySet();
for ( Iterator it=currentElements.iterator(); it.hasNext(); ) {
Object current = it.next();
if ( current!=null && ForeignKeys.isNotTransient(entityName, current, null, session) ) {
- Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
- currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
+ EntityEntry ee = session.getPersistenceContext().getEntry( current );
+ if ( ee != null && ee.getStatus() == Status.SAVING ) {
+ currentSaving.add( current );
+ }
+ else {
+ Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
+ currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
+ }
}
}
// iterate over the *old* list
for ( Iterator it=oldElements.iterator(); it.hasNext(); ) {
Object old = it.next();
- Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
- if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
- res.add(old);
+ if ( ! currentSaving.contains( old ) ) {
+ Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
+ if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
+ res.add(old);
+ }
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java 2010-07-20 01:04:51 UTC (rev 19968)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java 2010-07-20 01:22:12 UTC (rev 19969)
@@ -118,10 +118,8 @@
* Saves the child object with the parent when the one-to-many association
* uses cascade="all-delete-orphan" and the many-to-one association uses
* cascade="all"
- * <p/>
- * This test is known to fail. See HHH-2269.
*/
- public void testSaveOrphanDeleteChildWithParentFailureExpected() {
+ public void testSaveOrphanDeleteChildWithParent() {
Session session = openSession();
Transaction txn = session.beginTransaction();
Parent parent = new Parent();
14 years, 4 months
Hibernate SVN: r19968 - in core/branches/Branch_3_5: testsuite/src/test/java/org/hibernate/test/cascade and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-07-19 21:04:51 -0400 (Mon, 19 Jul 2010)
New Revision: 19968
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java
Log:
HHH-2269 : Many-to-one cascade fails with TransientObjectException if inverse collection is CascadeType.DELETE_ORPHAN
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java 2010-07-19 22:09:56 UTC (rev 19967)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/collection/AbstractPersistentCollection.java 2010-07-20 01:04:51 UTC (rev 19968)
@@ -36,14 +36,17 @@
import org.hibernate.HibernateException;
import org.hibernate.LazyInitializationException;
import org.hibernate.engine.CollectionEntry;
+import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.ForeignKeys;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.Status;
import org.hibernate.engine.TypedValue;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.EmptyIterator;
+import org.hibernate.util.IdentitySet;
import org.hibernate.util.MarkerObject;
/**
@@ -905,20 +908,29 @@
// collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
java.util.Set currentIds = new HashSet();
+ java.util.Set currentSaving = new IdentitySet();
for ( Iterator it=currentElements.iterator(); it.hasNext(); ) {
Object current = it.next();
if ( current!=null && ForeignKeys.isNotTransient(entityName, current, null, session) ) {
- Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
- currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
+ EntityEntry ee = session.getPersistenceContext().getEntry( current );
+ if ( ee != null && ee.getStatus() == Status.SAVING ) {
+ currentSaving.add( current );
+ }
+ else {
+ Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
+ currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
+ }
}
}
// iterate over the *old* list
for ( Iterator it=oldElements.iterator(); it.hasNext(); ) {
Object old = it.next();
- Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
- if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
- res.add(old);
+ if ( ! currentSaving.contains( old ) ) {
+ Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
+ if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
+ res.add(old);
+ }
}
}
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java 2010-07-19 22:09:56 UTC (rev 19967)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java 2010-07-20 01:04:51 UTC (rev 19968)
@@ -118,10 +118,8 @@
* Saves the child object with the parent when the one-to-many association
* uses cascade="all-delete-orphan" and the many-to-one association uses
* cascade="all"
- * <p/>
- * This test is known to fail. See HHH-2269.
*/
- public void testSaveOrphanDeleteChildWithParentFailureExpected() {
+ public void testSaveOrphanDeleteChildWithParent() {
Session session = openSession();
Transaction txn = session.beginTransaction();
Parent parent = new Parent();
14 years, 4 months
Hibernate SVN: r19967 - core/trunk/testsuite/src/test/java/org/hibernate/test/cascade.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-07-19 18:09:56 -0400 (Mon, 19 Jul 2010)
New Revision: 19967
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml
Log:
HHH-3334 : Added FailureExpected test for Cascade-save breaks if parent ID is assigned (delays insert) and child has identity ID (early insert)
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java 2010-07-19 22:09:56 UTC (rev 19967)
@@ -0,0 +1,119 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cascade;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.id.IdentityGenerator;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Wallace Wadge (based on code by Gail Badner)
+ */
+
+/**
+ * Test case to illustrate that when a child table attempts to cascade to a parent and the parent's Id
+ * is set to assigned, an exception thrown (not-null property references a null or transient value).
+ * This error only occurs if the parent link in marked as not nullable.
+ */
+public class CascadeTestWithAssignedParentIdTest extends FunctionalTestCase {
+
+ public CascadeTestWithAssignedParentIdTest(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] {
+ "cascade/ChildForParentWithAssignedId.hbm.xml",
+ "cascade/ParentWithAssignedId.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CascadeTestWithAssignedParentIdTest.class );
+ }
+
+
+ /**
+ * Saves the child object with the parent when both the one-to-many and
+ * many-to-one associations use cascade="all"
+ */
+ public void testSaveChildWithParentFailureExpected() {
+ if ( ! IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
+ reportSkip( "FailureExpected test passes when native id generator is not IdentityGenerator",
+ "parent insert is assigned (delayed) when child is identity (early insert)" );
+ fail( "test is expected to fail" );
+ return;
+ }
+ Session session = openSession();
+ Transaction txn = session.beginTransaction();
+ Parent parent = new Parent();
+ Child child = new Child();
+ child.setParent( parent );
+ parent.setChildren( Collections.singleton( child ) );
+ parent.setId(new Long(123L));
+ // this should figure out that the parent needs saving first since id is assigned.
+ session.save( child );
+ txn.commit();
+ session.close();
+
+ session = openSession();
+ txn = session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getId() );
+ assertEquals( 1, parent.getChildren().size() );
+ txn.commit();
+ session.close();
+ }
+
+ public void testSaveChildWithParent() {
+ if ( IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
+ reportSkip( "test is known to fail when native id generator is IdentityGenerator",
+ "parent insert is assigned (delayed) when child has identity (early insert)" );
+ return;
+ }
+ Session session = openSession();
+ Transaction txn = session.beginTransaction();
+ Parent parent = new Parent();
+ Child child = new Child();
+ child.setParent( parent );
+ parent.setChildren( Collections.singleton( child ) );
+ parent.setId(new Long(123L));
+ // this should figure out that the parent needs saving first since id is assigned.
+ session.save( child );
+ txn.commit();
+ session.close();
+
+ session = openSession();
+ txn = session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getId() );
+ assertEquals( 1, parent.getChildren().size() );
+ txn.commit();
+ session.close();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml 2010-07-19 22:09:56 UTC (rev 19967)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cascade">
+ <class name="Child" table="Child">
+ <id name="id" column="id" type="java.lang.Long">
+ <generator class="native"/>
+ </id>
+ <many-to-one name="parent" class="Parent" not-null="true" cascade="all" />
+ </class>
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml 2010-07-19 22:09:56 UTC (rev 19967)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cascade">
+ <class name="Parent" table="Parent">
+ <id name="id" column="id" type="java.lang.Long">
+ <generator class="assigned"/>
+ </id>
+ <set name="children" cascade="all" inverse="true">
+ <key column="parent"/>
+ <one-to-many class="Child"/>
+ </set>
+ </class>
+</hibernate-mapping>
14 years, 4 months
Hibernate SVN: r19966 - core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-07-19 17:52:35 -0400 (Mon, 19 Jul 2010)
New Revision: 19966
Added:
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml
Log:
HHH-3334 : Added FailureExpected test for Cascade-save breaks if parent ID is assigned (delays insert) and child has identity ID (early insert)
Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/CascadeTestWithAssignedParentIdTest.java 2010-07-19 21:52:35 UTC (rev 19966)
@@ -0,0 +1,119 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cascade;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.id.IdentityGenerator;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Wallace Wadge (based on code by Gail Badner)
+ */
+
+/**
+ * Test case to illustrate that when a child table attempts to cascade to a parent and the parent's Id
+ * is set to assigned, an exception thrown (not-null property references a null or transient value).
+ * This error only occurs if the parent link in marked as not nullable.
+ */
+public class CascadeTestWithAssignedParentIdTest extends FunctionalTestCase {
+
+ public CascadeTestWithAssignedParentIdTest(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] {
+ "cascade/ChildForParentWithAssignedId.hbm.xml",
+ "cascade/ParentWithAssignedId.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CascadeTestWithAssignedParentIdTest.class );
+ }
+
+
+ /**
+ * Saves the child object with the parent when both the one-to-many and
+ * many-to-one associations use cascade="all"
+ */
+ public void testSaveChildWithParentFailureExpected() {
+ if ( ! IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
+ reportSkip( "FailureExpected test passes when native id generator is not IdentityGenerator",
+ "parent insert is assigned (delayed) when child is identity (early insert)" );
+ fail( "test is expected to fail" );
+ return;
+ }
+ Session session = openSession();
+ Transaction txn = session.beginTransaction();
+ Parent parent = new Parent();
+ Child child = new Child();
+ child.setParent( parent );
+ parent.setChildren( Collections.singleton( child ) );
+ parent.setId(new Long(123L));
+ // this should figure out that the parent needs saving first since id is assigned.
+ session.save( child );
+ txn.commit();
+ session.close();
+
+ session = openSession();
+ txn = session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getId() );
+ assertEquals( 1, parent.getChildren().size() );
+ txn.commit();
+ session.close();
+ }
+
+ public void testSaveChildWithParent() {
+ if ( IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
+ reportSkip( "test is known to fail when native id generator is IdentityGenerator",
+ "parent insert is assigned (delayed) when child has identity (early insert)" );
+ return;
+ }
+ Session session = openSession();
+ Transaction txn = session.beginTransaction();
+ Parent parent = new Parent();
+ Child child = new Child();
+ child.setParent( parent );
+ parent.setChildren( Collections.singleton( child ) );
+ parent.setId(new Long(123L));
+ // this should figure out that the parent needs saving first since id is assigned.
+ session.save( child );
+ txn.commit();
+ session.close();
+
+ session = openSession();
+ txn = session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getId() );
+ assertEquals( 1, parent.getChildren().size() );
+ txn.commit();
+ session.close();
+ }
+}
Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ChildForParentWithAssignedId.hbm.xml 2010-07-19 21:52:35 UTC (rev 19966)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cascade">
+ <class name="Child" table="Child">
+ <id name="id" column="id" type="java.lang.Long">
+ <generator class="native"/>
+ </id>
+ <many-to-one name="parent" class="Parent" not-null="true" cascade="all" />
+ </class>
+</hibernate-mapping>
Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cascade/ParentWithAssignedId.hbm.xml 2010-07-19 21:52:35 UTC (rev 19966)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cascade">
+ <class name="Parent" table="Parent">
+ <id name="id" column="id" type="java.lang.Long">
+ <generator class="assigned"/>
+ </id>
+ <set name="children" cascade="all" inverse="true">
+ <key column="parent"/>
+ <one-to-many class="Child"/>
+ </set>
+ </class>
+</hibernate-mapping>
14 years, 4 months