Hibernate SVN: r18327 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-24 06:55:08 -0500 (Thu, 24 Dec 2009)
New Revision: 18327
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
Log:
HHH-4531 Derby dialect should not support comments
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-24 11:49:14 UTC (rev 18326)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-24 11:55:08 UTC (rev 18327)
@@ -110,6 +110,11 @@
public boolean supportsLimit() {
return isTenPointFiveReleaseOrNewer();
}
+
+ //HHH-4531
+ public boolean supportsCommentOn() {
+ return false;
+ }
public boolean supportsLimitOffset() {
return isTenPointFiveReleaseOrNewer();
15 years
Hibernate SVN: r18326 - in core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate: impl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-24 06:49:14 -0500 (Thu, 24 Dec 2009)
New Revision: 18326
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/Transaction.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
Log:
minor change, correct javadoc spell
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/Transaction.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/Transaction.java 2009-12-24 07:58:35 UTC (rev 18325)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/Transaction.java 2009-12-24 11:49:14 UTC (rev 18326)
@@ -105,7 +105,7 @@
* Again, this only returns information in relation to the
* local transaction, not the actual underlying transaction.
*
- * @return boolean Treu if this local transaction is still active.
+ * @return boolean True if this local transaction is still active.
*/
public boolean isActive() throws HibernateException;
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2009-12-24 07:58:35 UTC (rev 18325)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2009-12-24 11:49:14 UTC (rev 18326)
@@ -36,32 +36,28 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.LinkedHashSet;
+
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.transaction.TransactionManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.hibernate.AssertionFailure;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.EntityMode;
+import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.QueryException;
import org.hibernate.SessionFactory;
-import org.hibernate.StatelessSession;
import org.hibernate.SessionFactoryObserver;
-import org.hibernate.EntityNameResolver;
-import org.hibernate.EntityNameResolver;
-import org.hibernate.tuple.entity.EntityTuplizer;
+import org.hibernate.StatelessSession;
import org.hibernate.cache.CacheKey;
import org.hibernate.cache.CollectionRegion;
import org.hibernate.cache.EntityRegion;
@@ -113,16 +109,19 @@
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.hbm2ddl.SchemaValidator;
import org.hibernate.transaction.TransactionFactory;
+import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.AssociationType;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.EmptyIterator;
+import org.hibernate.util.ReflectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Concrete implementation of the <tt>SessionFactory</tt> interface. Has the following
- * responsibilites
+ * responsibilities
* <ul>
* <li>caches configuration settings (immutably)
* <li>caches "compiled" mappings ie. <tt>EntityPersister</tt>s and
@@ -1066,7 +1065,7 @@
private CurrentSessionContext buildCurrentSessionContext() {
String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
- // for backward-compatability
+ // for backward-compatibility
if ( impl == null && transactionManager != null ) {
impl = "jta";
}
15 years
Hibernate SVN: r18325 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-24 02:58:35 -0500 (Thu, 24 Dec 2009)
New Revision: 18325
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one (minor change for perf)
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 07:56:51 UTC (rev 18324)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 07:58:35 UTC (rev 18325)
@@ -106,13 +106,14 @@
*/
public final void setSession(SessionImplementor s) throws HibernateException {
if ( s != session ) {
- if ( isConnectedToSession() ) {
+ // check for s == null first, since it is least expensive
+ if ( s == null ){
+ unsetSession();
+ }
+ else if ( isConnectedToSession() ) {
//TODO: perhaps this should be some other RuntimeException...
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
}
- else if ( s == null ){
- unsetSession();
- }
else {
session = s;
}
15 years
Hibernate SVN: r18324 - core/trunk/core/src/main/java/org/hibernate/proxy.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-24 02:56:51 -0500 (Thu, 24 Dec 2009)
New Revision: 18324
Modified:
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one (minor change for perf)
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 03:14:34 UTC (rev 18323)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 07:56:51 UTC (rev 18324)
@@ -106,13 +106,14 @@
*/
public final void setSession(SessionImplementor s) throws HibernateException {
if ( s != session ) {
- if ( isConnectedToSession() ) {
+ // check for s == null first, since it is least expensive
+ if ( s == null ){
+ unsetSession();
+ }
+ else if ( isConnectedToSession() ) {
//TODO: perhaps this should be some other RuntimeException...
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
}
- else if ( s == null ){
- unsetSession();
- }
else {
session = s;
}
15 years
Hibernate SVN: r18323 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-23 22:14:34 -0500 (Wed, 23 Dec 2009)
New Revision: 18323
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one (removed cached EntityKey)
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 03:11:54 UTC (rev 18322)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 03:14:34 UTC (rev 18323)
@@ -46,7 +46,6 @@
private boolean unwrap;
private transient SessionImplementor session;
- private transient EntityKey entityKey; // cached value
/**
* For serialization from the non-pojo initializers (HHH-3309)
@@ -65,7 +64,6 @@
this.entityName = entityName;
this.id = id;
this.session = session;
- this.entityKey = generateEntityKeyOrNull();
}
/**
@@ -87,7 +85,6 @@
*/
public final void setIdentifier(Serializable id) {
this.id = id;
- entityKey = generateEntityKeyOrNull();
}
/**
@@ -118,18 +115,15 @@
}
else {
session = s;
- entityKey = generateEntityKeyOrNull();
}
}
}
- private EntityKey generateEntityKeyOrNull() {
- if ( getIdentifier() == null || session == null || entityName == null ) {
+ private static EntityKey generateEntityKeyOrNull(Serializable id, SessionImplementor s, String entityName) {
+ if ( id == null || s == null || entityName == null ) {
return null;
}
- return new EntityKey(
- getIdentifier(), session.getFactory().getEntityPersister( entityName ), session.getEntityMode()
- );
+ return new EntityKey( id, s.getFactory().getEntityPersister( entityName ), s.getEntityMode() );
}
/**
@@ -137,7 +131,6 @@
*/
public void unsetSession() {
session = null;
- entityKey = null;
}
/**
@@ -183,7 +176,8 @@
}
private Object getProxyOrNull() {
- if ( session != null && session.isOpen() && entityKey != null ) {
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
+ if ( entityKey != null && session != null && session.isOpen() ) {
return session.getPersistenceContext().getProxy( entityKey );
}
return null;
@@ -210,12 +204,8 @@
* do not initialize the proxy
*/
public final Object getImplementation(SessionImplementor s) throws HibernateException {
- final EntityKey entityKey = new EntityKey(
- getIdentifier(),
- s.getFactory().getEntityPersister( getEntityName() ),
- s.getEntityMode()
- );
- return s.getPersistenceContext().getEntity( entityKey );
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), s, getEntityName() );
+ return ( entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey ) );
}
/**
15 years
Hibernate SVN: r18322 - core/trunk/core/src/main/java/org/hibernate/proxy.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-23 22:11:54 -0500 (Wed, 23 Dec 2009)
New Revision: 18322
Modified:
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one (removed cached EntityKey)
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23 18:55:06 UTC (rev 18321)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24 03:11:54 UTC (rev 18322)
@@ -46,7 +46,6 @@
private boolean unwrap;
private transient SessionImplementor session;
- private transient EntityKey entityKey; // cached value
/**
* For serialization from the non-pojo initializers (HHH-3309)
@@ -65,7 +64,6 @@
this.entityName = entityName;
this.id = id;
this.session = session;
- this.entityKey = generateEntityKeyOrNull();
}
/**
@@ -87,7 +85,6 @@
*/
public final void setIdentifier(Serializable id) {
this.id = id;
- entityKey = generateEntityKeyOrNull();
}
/**
@@ -118,18 +115,15 @@
}
else {
session = s;
- entityKey = generateEntityKeyOrNull();
}
}
}
- private EntityKey generateEntityKeyOrNull() {
- if ( getIdentifier() == null || session == null || entityName == null ) {
+ private static EntityKey generateEntityKeyOrNull(Serializable id, SessionImplementor s, String entityName) {
+ if ( id == null || s == null || entityName == null ) {
return null;
}
- return new EntityKey(
- getIdentifier(), session.getFactory().getEntityPersister( entityName ), session.getEntityMode()
- );
+ return new EntityKey( id, s.getFactory().getEntityPersister( entityName ), s.getEntityMode() );
}
/**
@@ -137,7 +131,6 @@
*/
public void unsetSession() {
session = null;
- entityKey = null;
}
/**
@@ -183,7 +176,8 @@
}
private Object getProxyOrNull() {
- if ( session != null && session.isOpen() && entityKey != null ) {
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
+ if ( entityKey != null && session != null && session.isOpen() ) {
return session.getPersistenceContext().getProxy( entityKey );
}
return null;
@@ -210,12 +204,8 @@
* do not initialize the proxy
*/
public final Object getImplementation(SessionImplementor s) throws HibernateException {
- final EntityKey entityKey = new EntityKey(
- getIdentifier(),
- s.getFactory().getEntityPersister( getEntityName() ),
- s.getEntityMode()
- );
- return s.getPersistenceContext().getEntity( entityKey );
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), s, getEntityName() );
+ return ( entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey ) );
}
/**
15 years
Hibernate SVN: r18321 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/ops and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-23 13:55:06 -0500 (Wed, 23 Dec 2009)
New Revision: 18321
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23 18:38:09 UTC (rev 18320)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23 18:55:06 UTC (rev 18321)
@@ -46,6 +46,7 @@
private boolean unwrap;
private transient SessionImplementor session;
+ private transient EntityKey entityKey; // cached value
/**
* For serialization from the non-pojo initializers (HHH-3309)
@@ -64,6 +65,7 @@
this.entityName = entityName;
this.id = id;
this.session = session;
+ this.entityKey = generateEntityKeyOrNull();
}
/**
@@ -85,6 +87,7 @@
*/
public final void setIdentifier(Serializable id) {
this.id = id;
+ entityKey = generateEntityKeyOrNull();
}
/**
@@ -110,17 +113,31 @@
//TODO: perhaps this should be some other RuntimeException...
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
}
+ else if ( s == null ){
+ unsetSession();
+ }
else {
session = s;
+ entityKey = generateEntityKeyOrNull();
}
}
}
+ private EntityKey generateEntityKeyOrNull() {
+ if ( getIdentifier() == null || session == null || entityName == null ) {
+ return null;
+ }
+ return new EntityKey(
+ getIdentifier(), session.getFactory().getEntityPersister( entityName ), session.getEntityMode()
+ );
+ }
+
/**
* {@inheritDoc}
*/
public void unsetSession() {
session = null;
+ entityKey = null;
}
/**
@@ -162,11 +179,16 @@
* @return Value for property 'connectedToSession'.
*/
protected final boolean isConnectedToSession() {
- return session!=null &&
- session.isOpen() &&
- session.getPersistenceContext().containsProxy(this);
+ return getProxyOrNull() != null;
}
+ private Object getProxyOrNull() {
+ if ( session != null && session.isOpen() && entityKey != null ) {
+ return session.getPersistenceContext().getProxy( entityKey );
+ }
+ return null;
+ }
+
/**
* Return the underlying persistent object, initializing if necessary
*/
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-12-23 18:38:09 UTC (rev 18320)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-12-23 18:55:06 UTC (rev 18321)
@@ -6,6 +6,7 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.HibernateException;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.intercept.FieldInterceptionHelper;
@@ -388,6 +389,23 @@
assertTrue( s1.contains( child.getParent() ) );
Session s2 = openSession();
+ try {
+ s2.getTransaction().begin();
+ s2.saveOrUpdate( child );
+ fail();
+ }
+ catch ( HibernateException ex ) {
+ // expected because parent is connected to s1
+ }
+ finally {
+ s2.getTransaction().rollback();
+ }
+ s2.close();
+
+ s1.evict( child.getParent() );
+ assertFalse( s1.contains( child.getParent() ) );
+
+ s2 = openSession();
s2.getTransaction().begin();
s2.saveOrUpdate( child );
assertTrue( s2.contains( child ) );
15 years
Hibernate SVN: r18320 - in core/trunk: testsuite/src/test/java/org/hibernate/test/nonflushedchanges and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-12-23 13:38:09 -0500 (Wed, 23 Dec 2009)
New Revision: 18320
Modified:
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
core/trunk/testsuite/src/test/java/org/hibernate/test/nonflushedchanges/SaveOrUpdateTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a different one
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23 10:57:37 UTC (rev 18319)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23 18:38:09 UTC (rev 18320)
@@ -46,6 +46,7 @@
private boolean unwrap;
private transient SessionImplementor session;
+ private transient EntityKey entityKey; // cached value
/**
* For serialization from the non-pojo initializers (HHH-3309)
@@ -64,6 +65,7 @@
this.entityName = entityName;
this.id = id;
this.session = session;
+ this.entityKey = generateEntityKeyOrNull();
}
/**
@@ -85,6 +87,7 @@
*/
public final void setIdentifier(Serializable id) {
this.id = id;
+ entityKey = generateEntityKeyOrNull();
}
/**
@@ -110,17 +113,31 @@
//TODO: perhaps this should be some other RuntimeException...
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
}
+ else if ( s == null ){
+ unsetSession();
+ }
else {
session = s;
+ entityKey = generateEntityKeyOrNull();
}
}
}
+ private EntityKey generateEntityKeyOrNull() {
+ if ( getIdentifier() == null || session == null || entityName == null ) {
+ return null;
+ }
+ return new EntityKey(
+ getIdentifier(), session.getFactory().getEntityPersister( entityName ), session.getEntityMode()
+ );
+ }
+
/**
* {@inheritDoc}
*/
public void unsetSession() {
session = null;
+ entityKey = null;
}
/**
@@ -162,11 +179,16 @@
* @return Value for property 'connectedToSession'.
*/
protected final boolean isConnectedToSession() {
- return session!=null &&
- session.isOpen() &&
- session.getPersistenceContext().containsProxy(this);
+ return getProxyOrNull() != null;
}
+ private Object getProxyOrNull() {
+ if ( session != null && session.isOpen() && entityKey != null ) {
+ return session.getPersistenceContext().getProxy( entityKey );
+ }
+ return null;
+ }
+
/**
* Return the underlying persistent object, initializing if necessary
*/
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/nonflushedchanges/SaveOrUpdateTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/nonflushedchanges/SaveOrUpdateTest.java 2009-12-23 10:57:37 UTC (rev 18319)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/nonflushedchanges/SaveOrUpdateTest.java 2009-12-23 18:38:09 UTC (rev 18320)
@@ -5,6 +5,7 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
+import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
@@ -441,7 +442,24 @@
SimpleJtaTransactionManagerImpl.getInstance().begin();
Session s2 = openSession();
- s2.saveOrUpdate( child );
+ try {
+ s2.getTransaction().begin();
+ s2.saveOrUpdate( child );
+ fail();
+ }
+ catch ( HibernateException ex ) {
+ // expected because parent is connected to s1
+ }
+ finally {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ }
+
+ s1.evict( child.getParent() );
+ assertFalse( s1.contains( child.getParent() ) );
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ s2 = openSession();
+ s2.saveOrUpdate( child );
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
child = ( Node ) getOldToNewEntityRefMap().get( child );
assertTrue( s2.contains( child ) );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-12-23 10:57:37 UTC (rev 18319)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-12-23 18:38:09 UTC (rev 18320)
@@ -6,6 +6,7 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.HibernateException;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.intercept.FieldInterceptionHelper;
@@ -388,6 +389,23 @@
assertTrue( s1.contains( child.getParent() ) );
Session s2 = openSession();
+ try {
+ s2.getTransaction().begin();
+ s2.saveOrUpdate( child );
+ fail();
+ }
+ catch ( HibernateException ex ) {
+ // expected because parent is connected to s1
+ }
+ finally {
+ s2.getTransaction().rollback();
+ }
+ s2.close();
+
+ s1.evict( child.getParent() );
+ assertFalse( s1.contains( child.getParent() ) );
+
+ s2 = openSession();
s2.getTransaction().begin();
s2.saveOrUpdate( child );
assertTrue( s2.contains( child ) );
15 years
Hibernate SVN: r18319 - search/branches/v3_1_1_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-23 05:57:37 -0500 (Wed, 23 Dec 2009)
New Revision: 18319
Modified:
search/branches/v3_1_1_GA_CP/pom.xml
Log:
JBPAPP-3218 update db profile in hibernate eap 5 cp branch
Modified: search/branches/v3_1_1_GA_CP/pom.xml
===================================================================
--- search/branches/v3_1_1_GA_CP/pom.xml 2009-12-22 18:07:38 UTC (rev 18318)
+++ search/branches/v3_1_1_GA_CP/pom.xml 2009-12-23 10:57:37 UTC (rev 18319)
@@ -802,17 +802,6 @@
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/classloading/*.java</exclude>
- <exclude>**/WorkerTestCase.java</exclude>
- <exclude>**/AsyncWorkerTest.java</exclude>
- <exclude>**/SyncWorkerTest.java</exclude>
- <exclude>**/MassIndexTest.java</exclude>
- <exclude>**/SessionTest.java</exclude>
- <exclude>**/ReaderPerfTestCase.java</exclude>
- <exclude>**/SharedBufferedReaderPerfTest.java</exclude>
- <exclude>**/SharedReaderPerfTest.java</exclude>
- <exclude>**/NotSharedReaderPerfTest.java</exclude>
- <exclude>**/OptimizerTestCase.java</exclude>
- <exclude>**/IncrementalOptimizerStrategyTest.java</exclude>
</excludes>
</configuration>
</plugin>
15 years
Hibernate SVN: r18318 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: smarlow(a)redhat.com
Date: 2009-12-22 13:07:38 -0500 (Tue, 22 Dec 2009)
New Revision: 18318
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
Log:
HHH-4601 implement orphanRemoval for OneToMany. OneToOne is not yet done (see HHH-4725)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-12-22 15:08:07 UTC (rev 18317)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-12-22 18:07:38 UTC (rev 18318)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -1486,7 +1486,7 @@
}
}
bindManyToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade ),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, false),
joinColumns,
ann.optional(),
ignoreNotFound, onDeleteCascade,
@@ -1521,7 +1521,7 @@
}
}
bindOneToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade ),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, false),
joinColumns,
ann.optional(),
getFetchMode( ann.fetch() ),
@@ -1550,7 +1550,7 @@
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
- bindAny( getCascadeStrategy( null, hibernateCascade ), //@Any has not cascade attribute
+ bindAny( getCascadeStrategy( null, hibernateCascade, false), //@Any has not cascade attribute
joinColumns, onDeleteCascade, nullability,
propertyHolder, inferredData, entityBinder,
isIdentifierMapper, mappings );
@@ -1756,7 +1756,8 @@
collectionBinder.setTargetEntity(
mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
);
- collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade ) );
+ collectionBinder.setCascadeStrategy(
+ getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval()) );
collectionBinder.setOneToMany( true );
}
else if ( elementCollectionAnn != null
@@ -1783,7 +1784,7 @@
collectionBinder.setTargetEntity(
mappings.getReflectionManager().toXClass( manyToManyAnn.targetEntity() )
);
- collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade ) );
+ collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade, false) );
collectionBinder.setOneToMany( false );
}
else if ( property.isAnnotationPresent( ManyToAny.class ) ) {
@@ -1791,7 +1792,7 @@
collectionBinder.setTargetEntity(
mappings.getReflectionManager().toXClass( void.class )
);
- collectionBinder.setCascadeStrategy( getCascadeStrategy( null, hibernateCascade ) );
+ collectionBinder.setCascadeStrategy( getCascadeStrategy( null, hibernateCascade, false) );
collectionBinder.setOneToMany( false );
}
collectionBinder.setMappedBy( mappedBy );
@@ -2464,8 +2465,8 @@
}
private static String getCascadeStrategy(
- javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation
- ) {
+ javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation,
+ boolean orphanRemoval) {
EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType( ejbCascades );
CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ?
null :
@@ -2475,6 +2476,11 @@
hibernateCascadeSet.addAll( Arrays.asList( hibernateCascades ) );
}
+ if ( orphanRemoval ) {
+ hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN);
+ hibernateCascadeSet.add(CascadeType.REMOVE);
+ }
+
StringBuilder cascade = new StringBuilder();
for ( CascadeType aHibernateCascadeSet : hibernateCascadeSet ) {
switch ( aHibernateCascadeSet ) {
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-12-22 15:08:07 UTC (rev 18317)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-12-22 18:07:38 UTC (rev 18318)
@@ -309,8 +309,56 @@
s.close();
}
-
+ public void testCascadedDeleteOfChildEntitiesBug2() {
+ // Relationship is one SoccerTeam to many Players.
+ // Create a SoccerTeam (parent) and three Players (child).
+ // Verify that the count of Players is correct.
+ // Clear the SoccerTeam reference Players.
+ // The orphanRemoval should remove the Players automatically.
+ // @OneToMany(mappedBy="name", orphanRemoval=true)
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ SoccerTeam team = new SoccerTeam();
+ int teamid = team.getId();
+ Player player1 = new Player();
+ player1.setName("Shalrie Joseph");
+ team.addPlayer(player1);
+
+ Player player2 = new Player();
+ player2.setName("Taylor Twellman");
+ team.addPlayer(player2);
+
+ Player player3 = new Player();
+ player3.setName("Steve Ralston");
+ team.addPlayer(player3);
+ s.persist(team);
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ team = (SoccerTeam)s.merge(team);
+ int count = ( (Long) s.createQuery( "select count(*) from Player" ).iterate().next() ).intValue();
+ assertEquals("expected count of 3 but got = " + count, count, 3);
+
+ // clear references to players, this should orphan the players which should
+ // in turn trigger orphanRemoval logic.
+ team.getPlayers().clear();
+// count = ( (Long) s.createQuery( "select count(*) from Player" ).iterate().next() ).intValue();
+// assertEquals("expected count of 0 but got = " + count, count, 0);
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ count = ( (Long) s.createQuery( "select count(*) from Player" ).iterate().next() ).intValue();
+ assertEquals("expected count of 0 but got = " + count, count, 0);
+ tx.commit();
+ s.close();
+ }
+
public void testFilter() throws Exception {
Session s;
Transaction tx;
@@ -581,7 +629,9 @@
Topic.class,
Narrative.class,
Drill.class,
- PowerDrill.class
+ PowerDrill.class,
+ SoccerTeam.class,
+ Player.class
};
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java 2009-12-22 18:07:38 UTC (rev 18318)
@@ -0,0 +1,65 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.annotations.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+
+@Entity
+public class Player {
+
+ private int id;
+ private String name;
+ private SoccerTeam team;
+
+ @Id
+ @GeneratedValue
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Column(name="name")
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @ManyToOne
+ public SoccerTeam getTeam() {
+ return team;
+ }
+ public void setTeam(SoccerTeam team) {
+ this.team = team;
+ }
+}
\ No newline at end of file
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java 2009-12-22 18:07:38 UTC (rev 18318)
@@ -0,0 +1,63 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.annotations.entity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class SoccerTeam {
+ @Id
+ @GeneratedValue
+ private int id;
+ @OneToMany(mappedBy="team",
+ orphanRemoval=true,
+ cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
+ private Set<Player> players = new HashSet<Player>();
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Set<Player> getPlayers() {
+ return players;
+ }
+
+ public void addPlayer(Player val) {
+ players.add(val);
+ val.setTeam(this);
+ }
+
+}
\ No newline at end of file
15 years