Hibernate SVN: r10802 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-14 08:06:36 -0500 (Tue, 14 Nov 2006)
New Revision: 10802
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
Log:
hbmtemplate is a bit more informative now when running.
jpaconfiguration now supports entityresolver
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java 2006-11-14 13:04:45 UTC (rev 10801)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java 2006-11-14 13:06:36 UTC (rev 10802)
@@ -35,7 +35,7 @@
private Configuration cfg;
private File configurationFile;
private File propertyFile;
- private String entityResolver;
+ protected String entityResolver;
private String namingStrategy;
public ConfigurationTask() {
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java 2006-11-14 13:04:45 UTC (rev 10801)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java 2006-11-14 13:06:36 UTC (rev 10802)
@@ -69,6 +69,13 @@
}
public String getName() {
- return "generic exporter " + ((exporterClass==null) ? "" : exporterClass);
+ StringBuffer buf = new StringBuffer("generic exporter");
+ if(exporterClass!=null) {
+ buf.append( "class: " + exporterClass);
+ }
+ if(templateName!=null) {
+ buf.append( "template: " + templateName);
+ }
+ return buf.toString();
}
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-11-14 13:04:45 UTC (rev 10801)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-11-14 13:06:36 UTC (rev 10802)
@@ -9,6 +9,7 @@
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.util.ReflectHelper;
+import org.xml.sax.EntityResolver;
public class JPAConfigurationTask extends ConfigurationTask {
@@ -24,6 +25,14 @@
Class clazz = ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration", JPAConfigurationTask.class);
Object ejb3cfg = clazz.newInstance();
+
+ if(entityResolver!=null) {
+ Class resolver = ReflectHelper.classForName(entityResolver, this.getClass());
+ Object object = resolver.newInstance();
+ Method method = clazz.getMethod("setEntityResolver", new Class[] { EntityResolver.class });
+ method.invoke(ejb3cfg, new Object[] { object } );
+ }
+
Method method = clazz.getMethod("configure", new Class[] { String.class, Map.class });
if ( method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides } ) == null ) {
throw new BuildException("Persistence unit not found: '" + persistenceUnit + "'.");
@@ -63,10 +72,6 @@
complain("configurationfile");
}
- public void setEntityResolver(String entityResolverName) {
- complain("entityresolver");
- }
-
private void complain(String param) {
throw new BuildException("<" + getTaskName() + "> currently only support autodiscovery from META-INF/persistence.xml. Thus setting the " + param + " attribute is not allowed");
}
17 years, 5 months
Hibernate SVN: r10801 - branches/Branch_3_2/HibernateExt/tools/doc/reference/en/modules
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-14 08:04:45 -0500 (Tue, 14 Nov 2006)
New Revision: 10801
Modified:
branches/Branch_3_2/HibernateExt/tools/doc/reference/en/modules/ant.xml
Log:
document HBX-816/HBX-840 (haltonerror for hbm2ddl)
Modified: branches/Branch_3_2/HibernateExt/tools/doc/reference/en/modules/ant.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-11-13 19:34:44 UTC (rev 10800)
+++ branches/Branch_3_2/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-11-14 13:04:45 UTC (rev 10801)
@@ -475,6 +475,7 @@
<area coords="7 55" id="ycfg6" />
<area coords="8 55" id="ycfg7" />
+ <area coords="8 55" id="ycfg8" />
</areaspec>
<programlisting><![CDATA[<hbm2ddl
@@ -485,6 +486,7 @@
outputfilename="filename.ddl"
delimiter=";"
format="true|false"
+ haltonerror="true|false"
>]]></programlisting>
<calloutlist>
@@ -527,6 +529,11 @@
<para>format (default: false): Apply basic formatting to the
statements.</para>
</callout>
+
+ <callout arearefs="ycfg8">
+ <para>haltonerror (default: false): Halt build process if an error occurs.</para>
+ </callout>
+
</calloutlist>
</programlistingco></para>
17 years, 5 months
Hibernate SVN: r10800 - branches/Branch_3_2/Hibernate3/src/org/hibernate/engine
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 14:34:44 -0500 (Mon, 13 Nov 2006)
New Revision: 10800
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadeStyle.java
Log:
HHH-2057 : add 'remove' as a sort-of alias for 'delete' in CascadingStyle;
+ javadocs
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadeStyle.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadeStyle.java 2006-11-13 19:34:33 UTC (rev 10799)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/CascadeStyle.java 2006-11-13 19:34:44 UTC (rev 10800)
@@ -9,27 +9,44 @@
import org.hibernate.util.ArrayHelper;
/**
- * A style of cascade that can be specified by the mapping for an association.
- * The style is specified by the <tt>cascade</tt> attribute in the mapping file.
+ * A contract for defining the aspects of cascading various persistence actions.
+ *
+ * @see CascadingAction
*
* @author Gavin King
*/
public abstract class CascadeStyle implements Serializable {
-
+
/**
- * Should the given action be cascaded?
+ * For this style, should the given action be cascaded?
+ *
+ * @param action The action to be checked for cascade-ability.
+ * @return True if the action should be cascaded under this style; false otherwise.
*/
public abstract boolean doCascade(CascadingAction action);
/**
- * Should the given action really, really be cascaded?
+ * Probably more aptly named something like doCascadeToCollectionElements(); it is
+ * however used from both the collection and to-one logic branches...
+ * <p/>
+ * For this style, should the given action really be cascaded? The default
+ * implementation is simply to return {@link #doCascade}; for certain
+ * styles (currently only delete-orphan), however, we need to be able to
+ * control this seperately.
+ *
+ * @param action The action to be checked for cascade-ability.
+ * @return True if the action should be really cascaded under this style;
+ * false otherwise.
*/
public boolean reallyDoCascade(CascadingAction action) {
return doCascade(action);
}
-
+
/**
* Do we need to delete orphaned collection elements?
+ *
+ * @return True if this style need to account for orphan delete
+ * operations; false othwerwise.
*/
public boolean hasOrphanDelete() {
return false;
@@ -215,25 +232,37 @@
return "STYLE_NONE";
}
};
-
- CascadeStyle() {}
-
+
+ /**
+ * package-protected constructor
+ */
+ CascadeStyle() {
+ }
+
static final Map STYLES = new HashMap();
+
static {
- STYLES.put("all", ALL);
- STYLES.put("all-delete-orphan", ALL_DELETE_ORPHAN);
- STYLES.put("save-update", UPDATE);
- STYLES.put("persist", PERSIST);
- STYLES.put("merge", MERGE);
- STYLES.put("lock", LOCK);
- STYLES.put("refresh", REFRESH);
- STYLES.put("replicate", REPLICATE);
- STYLES.put("evict", EVICT);
- STYLES.put("delete", DELETE);
- STYLES.put("delete-orphan", DELETE_ORPHAN);
- STYLES.put("none", NONE);
+ STYLES.put( "all", ALL );
+ STYLES.put( "all-delete-orphan", ALL_DELETE_ORPHAN );
+ STYLES.put( "save-update", UPDATE );
+ STYLES.put( "persist", PERSIST );
+ STYLES.put( "merge", MERGE );
+ STYLES.put( "lock", LOCK );
+ STYLES.put( "refresh", REFRESH );
+ STYLES.put( "replicate", REPLICATE );
+ STYLES.put( "evict", EVICT );
+ STYLES.put( "delete", DELETE );
+ STYLES.put( "remove", DELETE ); // adds remove as a sort-of alias for delete...
+ STYLES.put( "delete-orphan", DELETE_ORPHAN );
+ STYLES.put( "none", NONE );
}
-
+
+ /**
+ * Factory method for obtaining named cascade styles
+ *
+ * @param cascade The named cascade style name.
+ * @return The appropriate CascadeStyle
+ */
public static CascadeStyle getCascadeStyle(String cascade) {
CascadeStyle style = (CascadeStyle) STYLES.get(cascade);
if (style==null) {
17 years, 5 months
Hibernate SVN: r10799 - trunk/Hibernate3/src/org/hibernate/engine
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 14:34:33 -0500 (Mon, 13 Nov 2006)
New Revision: 10799
Modified:
trunk/Hibernate3/src/org/hibernate/engine/CascadeStyle.java
Log:
HHH-2057 : add 'remove' as a sort-of alias for 'delete' in CascadingStyle;
+ javadocs
Modified: trunk/Hibernate3/src/org/hibernate/engine/CascadeStyle.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/CascadeStyle.java 2006-11-13 19:21:30 UTC (rev 10798)
+++ trunk/Hibernate3/src/org/hibernate/engine/CascadeStyle.java 2006-11-13 19:34:33 UTC (rev 10799)
@@ -9,27 +9,44 @@
import org.hibernate.util.ArrayHelper;
/**
- * A style of cascade that can be specified by the mapping for an association.
- * The style is specified by the <tt>cascade</tt> attribute in the mapping file.
- *
+ * A contract for defining the aspects of cascading various persistence actions.
+ *
+ * @see CascadingAction
+ *
* @author Gavin King
*/
public abstract class CascadeStyle implements Serializable {
-
+
/**
- * Should the given action be cascaded?
+ * For this style, should the given action be cascaded?
+ *
+ * @param action The action to be checked for cascade-ability.
+ * @return True if the action should be cascaded under this style; false otherwise.
*/
public abstract boolean doCascade(CascadingAction action);
-
+
/**
- * Should the given action really, really be cascaded?
+ * Probably more aptly named something like doCascadeToCollectionElements(); it is
+ * however used from both the collection and to-one logic branches...
+ * <p/>
+ * For this style, should the given action really be cascaded? The default
+ * implementation is simply to return {@link #doCascade}; for certain
+ * styles (currently only delete-orphan), however, we need to be able to
+ * control this seperately.
+ *
+ * @param action The action to be checked for cascade-ability.
+ * @return True if the action should be really cascaded under this style;
+ * false otherwise.
*/
public boolean reallyDoCascade(CascadingAction action) {
return doCascade(action);
}
-
+
/**
* Do we need to delete orphaned collection elements?
+ *
+ * @return True if this style need to account for orphan delete
+ * operations; false othwerwise.
*/
public boolean hasOrphanDelete() {
return false;
@@ -62,7 +79,7 @@
return ArrayHelper.toString(styles);
}
}
-
+
/**
* save / delete / update / evict / lock / replicate / merge / persist + delete orphans
*/
@@ -77,7 +94,7 @@
return "STYLE_ALL_DELETE_ORPHAN";
}
};
-
+
/**
* save / delete / update / evict / lock / replicate / merge / persist
*/
@@ -89,7 +106,7 @@
return "STYLE_ALL";
}
};
-
+
/**
* save / update
*/
@@ -101,7 +118,7 @@
return "STYLE_SAVE_UPDATE";
}
};
-
+
/**
* lock
*/
@@ -113,7 +130,7 @@
return "STYLE_LOCK";
}
};
-
+
/**
* refresh
*/
@@ -125,7 +142,7 @@
return "STYLE_REFRESH";
}
};
-
+
/**
* evict
*/
@@ -137,7 +154,7 @@
return "STYLE_EVICT";
}
};
-
+
/**
* replicate
*/
@@ -160,7 +177,7 @@
return "STYLE_MERGE";
}
};
-
+
/**
* create
*/
@@ -173,7 +190,7 @@
return "STYLE_PERSIST";
}
};
-
+
/**
* delete
*/
@@ -185,7 +202,7 @@
return "STYLE_DELETE";
}
};
-
+
/**
* delete + delete orphans
*/
@@ -203,7 +220,7 @@
return "STYLE_DELETE_ORPHAN";
}
};
-
+
/**
* no cascades
*/
@@ -215,25 +232,37 @@
return "STYLE_NONE";
}
};
-
- CascadeStyle() {}
-
+
+ /**
+ * package-protected constructor
+ */
+ CascadeStyle() {
+ }
+
static final Map STYLES = new HashMap();
+
static {
- STYLES.put("all", ALL);
- STYLES.put("all-delete-orphan", ALL_DELETE_ORPHAN);
- STYLES.put("save-update", UPDATE);
- STYLES.put("persist", PERSIST);
- STYLES.put("merge", MERGE);
- STYLES.put("lock", LOCK);
- STYLES.put("refresh", REFRESH);
- STYLES.put("replicate", REPLICATE);
- STYLES.put("evict", EVICT);
- STYLES.put("delete", DELETE);
- STYLES.put("delete-orphan", DELETE_ORPHAN);
- STYLES.put("none", NONE);
+ STYLES.put( "all", ALL );
+ STYLES.put( "all-delete-orphan", ALL_DELETE_ORPHAN );
+ STYLES.put( "save-update", UPDATE );
+ STYLES.put( "persist", PERSIST );
+ STYLES.put( "merge", MERGE );
+ STYLES.put( "lock", LOCK );
+ STYLES.put( "refresh", REFRESH );
+ STYLES.put( "replicate", REPLICATE );
+ STYLES.put( "evict", EVICT );
+ STYLES.put( "delete", DELETE );
+ STYLES.put( "remove", DELETE ); // adds remove as a sort-of alias for delete...
+ STYLES.put( "delete-orphan", DELETE_ORPHAN );
+ STYLES.put( "none", NONE );
}
-
+
+ /**
+ * Factory method for obtaining named cascade styles
+ *
+ * @param cascade The named cascade style name.
+ * @return The appropriate CascadeStyle
+ */
public static CascadeStyle getCascadeStyle(String cascade) {
CascadeStyle style = (CascadeStyle) STYLES.get(cascade);
if (style==null) {
@@ -241,6 +270,6 @@
}
else {
return style;
- }
+ }
}
}
17 years, 5 months
Hibernate SVN: r10798 - branches/Branch_3_2/Hibernate3/etc
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 14:21:30 -0500 (Mon, 13 Nov 2006)
New Revision: 10798
Modified:
branches/Branch_3_2/Hibernate3/etc/hibernate.properties
Log:
example property settings for InterSystems' Cache SQL
Modified: branches/Branch_3_2/Hibernate3/etc/hibernate.properties
===================================================================
--- branches/Branch_3_2/Hibernate3/etc/hibernate.properties 2006-11-13 19:21:19 UTC (rev 10797)
+++ branches/Branch_3_2/Hibernate3/etc/hibernate.properties 2006-11-13 19:21:30 UTC (rev 10798)
@@ -233,7 +233,15 @@
#hibernate.connection.password hibernate
+## InterSystems Cache
+#hibernate.dialect org.hibernate.dialect.Cache71Dialect
+#hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
+#hibernate.connection.username _SYSTEM
+#hibernate.connection.password SYS
+#hibernate.connection.url jdbc:Cache://127.0.0.1:1972/HIBERNATE
+
+
#################################
### Hibernate Connection Pool ###
#################################
17 years, 5 months
Hibernate SVN: r10797 - trunk/Hibernate3/etc
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 14:21:19 -0500 (Mon, 13 Nov 2006)
New Revision: 10797
Modified:
trunk/Hibernate3/etc/hibernate.properties
Log:
example property settings for InterSystems' Cache SQL
Modified: trunk/Hibernate3/etc/hibernate.properties
===================================================================
--- trunk/Hibernate3/etc/hibernate.properties 2006-11-13 18:53:57 UTC (rev 10796)
+++ trunk/Hibernate3/etc/hibernate.properties 2006-11-13 19:21:19 UTC (rev 10797)
@@ -233,7 +233,15 @@
#hibernate.connection.password hibernate
+## InterSystems Cache
+#hibernate.dialect org.hibernate.dialect.Cache71Dialect
+#hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
+#hibernate.connection.username _SYSTEM
+#hibernate.connection.password SYS
+#hibernate.connection.url jdbc:Cache://127.0.0.1:1972/HIBERNATE
+
+
#################################
### Hibernate Connection Pool ###
#################################
17 years, 5 months
Hibernate SVN: r10796 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/event/def test/org/hibernate/test/discriminator test/org/hibernate/test/joinedsubclass
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 13:53:57 -0500 (Mon, 13 Nov 2006)
New Revision: 10796
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java
Log:
HHH-1460 : subclass/get consistency
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-11-13 18:52:33 UTC (rev 10795)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-11-13 18:53:57 UTC (rev 10796)
@@ -8,7 +8,6 @@
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException;
-import org.hibernate.ObjectDeletedException;
import org.hibernate.PersistentObjectException;
import org.hibernate.TypeMismatchException;
import org.hibernate.EntityMode;
@@ -43,9 +42,12 @@
*/
public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener implements LoadEventListener {
+ public static final Object REMOVED_ENTITY_MARKER = new Object();
+ public static final Object INCONSISTENT_RTN_CLASS_MARKER = new Object();
+ public static final LockMode DEFAULT_LOCK_MODE = LockMode.NONE;
+
private static final Log log = LogFactory.getLog(DefaultLoadEventListener.class);
- public static final LockMode DEFAULT_LOCK_MODE = LockMode.NONE;
/**
* Handle the given load event.
@@ -306,7 +308,6 @@
return proxy;
}
- protected static final Object REMOVED_ENTITY_MARKER = new Object();
/**
* Coordinates the efforts to load a given entity. First, an attempt is
@@ -314,15 +315,18 @@
* an attempt is made to locate it in second-level cache. Lastly, an
* attempt is made to load it directly from the datasource.
*
- * @return The loaded entity.
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
+ * @return The loaded entity, or null.
* @throws HibernateException
*/
protected Object doLoad(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
if ( log.isTraceEnabled() ) {
log.trace(
@@ -331,11 +335,15 @@
);
}
- Object entity = loadFromSessionCache(event, keyToLoad, options);
+ Object entity = loadFromSessionCache( event, keyToLoad, options );
if ( entity == REMOVED_ENTITY_MARKER ) {
log.debug( "load request found matching entity in context, but it is scheduled for removal; returning null" );
return null;
}
+ if ( entity == INCONSISTENT_RTN_CLASS_MARKER ) {
+ log.debug( "load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null" );
+ return null;
+ }
if ( entity != null ) {
if ( log.isTraceEnabled() ) {
log.trace(
@@ -346,13 +354,6 @@
return entity;
}
- // Entity not found in session; before going any further, see if we
- // already determined that this entity does not exist
- /*if ( event.getSession().getPersistenceContext().isNonExistant(keyToLoad) ) {
- if ( log.isTraceEnabled() ) log.trace("entity does not exist");
- return null;
- }*/
-
entity = loadFromSecondLevelCache(event, persister, options);
if ( entity != null ) {
if ( log.isTraceEnabled() ) {
@@ -378,30 +379,26 @@
* Performs the process of loading an entity from the configured
* underlying datasource.
*
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
* @return The object loaded from the datasource, or null if not found.
* @throws HibernateException
*/
protected Object loadFromDatasource(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
-
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
final SessionImplementor source = event.getSession();
-
Object entity = persister.load(
- event.getEntityId(),
- event.getInstanceToLoad(),
- event.getLockMode(),
+ event.getEntityId(),
+ event.getInstanceToLoad(),
+ event.getLockMode(),
source
- );
-
- /*if ( entity == null ) {
- //remember it doesn't exist, in case of next time
- source.getPersistenceContext().addNonExistantEntityKey(keyToLoad);
- }*/
-
+ );
+
if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
}
@@ -410,22 +407,30 @@
}
/**
- * Attempts to locate the entity in the session-level cache. If
- * checkDeleted was set to true, then if the entity is found in the
+ * Attempts to locate the entity in the session-level cache.
+ * <p/>
+ * If allowed to return nulls, then if the entity happens to be found in
+ * the session cache, we check the entity type for proper handling
+ * of entity hierarchies.
+ * <p/>
+ * If checkDeleted was set to true, then if the entity is found in the
* session-level cache, it's current status within the session cache
* is checked to see if it has previously been scheduled for deletion.
*
+ * @param event The load event
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
* @return The entity from the session-level cache, or null.
- * @throws HibernateException
+ * @throws HibernateException Generally indicates problems applying a lock-mode.
*/
protected Object loadFromSessionCache(
- final LoadEvent event,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
+ final LoadEvent event,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
SessionImplementor session = event.getSession();
Object old = session.getEntityUsingInterceptor( keyToLoad );
+
if ( old != null ) {
// this object was already loaded
EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
@@ -435,22 +440,31 @@
return REMOVED_ENTITY_MARKER;
}
}
+ if ( options.isAllowNulls() ) {
+ EntityPersister persister = event.getSession().getFactory().getEntityPersister( event.getEntityClassName() );
+ if ( ! persister.isInstance( old, event.getSession().getEntityMode() ) ) {
+ return INCONSISTENT_RTN_CLASS_MARKER;
+ }
+ }
upgradeLock( old, oldEntry, event.getLockMode(), session );
}
+
return old;
}
/**
* Attempts to load the entity from the second-level cache.
*
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param options The load options.
* @return The entity from the second-level cache, or null.
* @throws HibernateException
*/
protected Object loadFromSecondLevelCache(
- final LoadEvent event,
- final EntityPersister persister,
- final LoadEventListener.LoadType options)
- throws HibernateException {
+ final LoadEvent event,
+ final EntityPersister persister,
+ final LoadEventListener.LoadType options) throws HibernateException {
final SessionImplementor source = event.getSession();
@@ -504,11 +518,10 @@
}
private Object assembleCacheEntry(
- final CacheEntry entry,
- final Serializable id,
- final EntityPersister persister,
- final LoadEvent event)
- throws HibernateException {
+ final CacheEntry entry,
+ final Serializable id,
+ final EntityPersister persister,
+ final LoadEvent event) throws HibernateException {
final Object optionalObject = event.getInstanceToLoad();
final EventSource session = event.getSession();
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java 2006-11-13 18:52:33 UTC (rev 10795)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java 2006-11-13 18:53:57 UTC (rev 10796)
@@ -3,6 +3,7 @@
import java.util.Iterator;
import java.util.List;
+import java.math.BigDecimal;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -10,6 +11,7 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.criterion.Property;
import org.hibernate.test.TestCase;
/**
@@ -20,11 +22,11 @@
public DiscriminatorTest(String str) {
super(str);
}
-
- public void testJoinedSubclass() {
+
+ public void testDiscriminatorSubclass() {
Session s = openSession();
Transaction t = s.beginTransaction();
-
+
Employee mark = new Employee();
mark.setName("Mark");
mark.setTitle("internal sales");
@@ -32,7 +34,7 @@
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
-
+
Customer joe = new Customer();
joe.setName("Joe");
joe.setAddress("San Francisco");
@@ -41,17 +43,17 @@
joe.setComments("Very demanding");
joe.setSex('M');
joe.setSalesperson(mark);
-
+
Person yomomma = new Person();
yomomma.setName("mum");
yomomma.setSex('F');
-
+
s.save(yomomma);
s.save(mark);
s.save(joe);
-
+
assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
-
+
assertEquals( s.createQuery("from Person").list().size(), 3 );
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
@@ -65,7 +67,7 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
customers = s.createQuery("from Customer").list();
for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
Customer c = (Customer) iter.next();
@@ -74,11 +76,11 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
-
+
mark.setZip("30306");
assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
s.delete(mark);
@@ -89,6 +91,78 @@
s.close();
}
+ public void testAccessAsIncorrectSubclass() {
+ Session s = openSession();
+ s.beginTransaction();
+ Employee e = new Employee();
+ e.setName( "Steve" );
+ e.setSex( 'M' );
+ e.setTitle( "grand poobah" );
+ s.save( e );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Customer c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ e = ( Employee ) s.get( Employee.class, new Long( e.getId() ) );
+ c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNotNull( e );
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testQuerySubclassAttribute() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName("Emmanuel");
+ p.setSex('M');
+ s.persist(p);
+ Employee q = new Employee();
+ q.setName("Steve");
+ q.setSex('M');
+ q.setTitle("Mr");
+ q.setSalary( new BigDecimal(1000) );
+ s.persist(q);
+
+ List result = s.createQuery("from Person where salary > 100").list();
+ assertEquals( result.size(), 1 );
+ assertSame( result.get(0), q );
+
+ result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
+ assertEquals( result.size(), 2 );
+
+ result = s.createCriteria(Person.class)
+ .add( Property.forName("salary").gt( new BigDecimal(100) ) )
+ .list();
+ assertEquals( result.size(), 1 );
+ assertSame( result.get(0), q );
+
+ //TODO: make this work:
+ /*result = s.createQuery("select salary from Person where salary > 100").list();
+ assertEquals( result.size(), 1 );
+ assertEquals( result.get(0), new BigDecimal(1000) );*/
+
+ s.delete(p);
+ s.delete(q);
+ t.commit();
+ s.close();
+ }
+
protected String[] getMappings() {
return new String[] { "discriminator/Person.hbm.xml" };
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-11-13 18:52:33 UTC (rev 10795)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-11-13 18:53:57 UTC (rev 10796)
@@ -14,10 +14,6 @@
import org.hibernate.LockMode;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Property;
-import org.hibernate.dialect.DB2Dialect;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.test.TestCase;
/**
@@ -28,11 +24,11 @@
public JoinedSubclassTest(String str) {
super(str);
}
-
+
public void testJoinedSubclass() {
Session s = openSession();
Transaction t = s.beginTransaction();
-
+
Employee mark = new Employee();
mark.setName("Mark");
mark.setTitle("internal sales");
@@ -40,7 +36,7 @@
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
-
+
Customer joe = new Customer();
joe.setName("Joe");
joe.setAddress("San Francisco");
@@ -49,17 +45,17 @@
joe.setComments("Very demanding");
joe.setSex('M');
joe.setSalesperson(mark);
-
+
Person yomomma = new Person();
yomomma.setName("mum");
yomomma.setSex('F');
-
+
s.save(yomomma);
s.save(mark);
s.save(joe);
-
+
assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
-
+
assertEquals( s.createQuery("from Person").list().size(), 3 );
assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
@@ -73,7 +69,7 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
customers = s.createQuery("from Customer").list();
for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
Customer c = (Customer) iter.next();
@@ -82,20 +78,20 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
-
+
mark.setZip("30306");
assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
if ( supportsRowValueConstructorSyntaxInInList() ) {
- s.createCriteria(Person.class).add(
- Expression.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )
+ s.createCriteria(Person.class).add(
+ Expression.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )
).list();
}
-
+
s.delete(mark);
s.delete(joe);
s.delete(yomomma);
@@ -103,6 +99,40 @@
t.commit();
s.close();
}
+
+ public void testAccessAsIncorrectSubclass() {
+ Session s = openSession();
+ s.beginTransaction();
+ Employee e = new Employee();
+ e.setName( "Steve" );
+ e.setSex( 'M' );
+ e.setTitle( "grand poobah" );
+ s.save( e );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Customer c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ e = ( Employee ) s.get( Employee.class, new Long( e.getId() ) );
+ c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNotNull( e );
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e );
+ s.getTransaction().commit();
+ s.close();
+ }
public void testQuerySubclassAttribute() {
Session s = openSession();
17 years, 5 months
Hibernate SVN: r10795 - in trunk/Hibernate3: src/org/hibernate/event/def test/org/hibernate/test/discriminator test/org/hibernate/test/joinedsubclass
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 13:52:33 -0500 (Mon, 13 Nov 2006)
New Revision: 10795
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
trunk/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java
trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java
Log:
HHH-1460 : subclass/get consistency
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-11-13 18:47:46 UTC (rev 10794)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-11-13 18:52:33 UTC (rev 10795)
@@ -8,7 +8,6 @@
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException;
-import org.hibernate.ObjectDeletedException;
import org.hibernate.PersistentObjectException;
import org.hibernate.TypeMismatchException;
import org.hibernate.EntityMode;
@@ -43,11 +42,14 @@
*/
public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener implements LoadEventListener {
+ public static final Object REMOVED_ENTITY_MARKER = new Object();
+ public static final Object INCONSISTENT_RTN_CLASS_MARKER = new Object();
+ public static final LockMode DEFAULT_LOCK_MODE = LockMode.NONE;
+
private static final Log log = LogFactory.getLog(DefaultLoadEventListener.class);
- public static final LockMode DEFAULT_LOCK_MODE = LockMode.NONE;
- /**
+ /**
* Handle the given load event.
*
* @param event The load event to be handled.
@@ -67,9 +69,9 @@
}
if ( persister == null ) {
- throw new HibernateException(
- "Unable to locate persister: " +
- event.getEntityClassName()
+ throw new HibernateException(
+ "Unable to locate persister: " +
+ event.getEntityClassName()
);
}
@@ -118,12 +120,12 @@
* @throws HibernateException
*/
protected Object load(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
final LoadEventListener.LoadType options)
throws HibernateException {
-
+
if ( event.getInstanceToLoad() != null ) {
if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
throw new PersistentObjectException(
@@ -135,9 +137,9 @@
}
Object entity = doLoad(event, persister, keyToLoad, options);
-
+
boolean isOptionalInstance = event.getInstanceToLoad() != null;
-
+
if ( !options.isAllowNulls() || isOptionalInstance ) {
if ( entity == null ) {
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );
@@ -151,7 +153,7 @@
return entity;
}
- /**
+ /**
* Based on configured options, will either return a pre-existing proxy,
* generate a new proxy, or perform an actual load.
*
@@ -159,15 +161,15 @@
* @throws HibernateException
*/
protected Object proxyOrLoad(
- final LoadEvent event,
+ final LoadEvent event,
final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options)
throws HibernateException {
-
+
if ( log.isTraceEnabled() ) {
log.trace(
- "loading entity: " +
+ "loading entity: " +
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
);
}
@@ -193,7 +195,7 @@
return load(event, persister, keyToLoad, options);
}
}
-
+
}
}
@@ -202,11 +204,11 @@
* Initialize it if necessary; narrow if necessary.
*/
private Object returnNarrowedProxy(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options,
- final PersistenceContext persistenceContext,
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options,
+ final PersistenceContext persistenceContext,
final Object proxy
) {
log.trace("entity proxy found in session cache");
@@ -223,16 +225,16 @@
}
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
}
-
+
/**
* Given that there is no pre-existing proxy.
* Check if the entity is already loaded. If it is, return the entity,
* otherwise create and return a proxy.
*/
private Object createProxyIfNecessary(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
final LoadEventListener.LoadType options,
final PersistenceContext persistenceContext
) {
@@ -259,7 +261,7 @@
}
}
- /**
+ /**
* If the class to be loaded has been configured with a cache, then lock
* given id in that cache and then perform the load.
*
@@ -267,22 +269,22 @@
* @throws HibernateException
*/
protected Object lockAndLoad(
- final LoadEvent event,
+ final LoadEvent event,
final EntityPersister persister,
- final EntityKey keyToLoad,
+ final EntityKey keyToLoad,
final LoadEventListener.LoadType options,
- final SessionImplementor source)
+ final SessionImplementor source)
throws HibernateException {
-
+
CacheConcurrencyStrategy.SoftLock lock = null;
final CacheKey ck;
if ( persister.hasCache() ) {
- ck = new CacheKey(
- event.getEntityId(),
- persister.getIdentifierType(),
- persister.getRootEntityName(),
- source.getEntityMode(),
- source.getFactory()
+ ck = new CacheKey(
+ event.getEntityId(),
+ persister.getIdentifierType(),
+ persister.getRootEntityName(),
+ source.getEntityMode(),
+ source.getFactory()
);
lock = persister.getCache().lock(ck, null );
}
@@ -302,11 +304,10 @@
Object proxy = event.getSession().getPersistenceContext()
.proxyFor( persister, keyToLoad, entity );
-
+
return proxy;
}
- protected static final Object REMOVED_ENTITY_MARKER = new Object();
/**
* Coordinates the efforts to load a given entity. First, an attempt is
@@ -314,28 +315,35 @@
* an attempt is made to locate it in second-level cache. Lastly, an
* attempt is made to load it directly from the datasource.
*
- * @return The loaded entity.
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
+ * @return The loaded entity, or null.
* @throws HibernateException
*/
protected Object doLoad(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
-
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
+
if ( log.isTraceEnabled() ) {
log.trace(
- "attempting to resolve: " +
+ "attempting to resolve: " +
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
);
}
- Object entity = loadFromSessionCache(event, keyToLoad, options);
+ Object entity = loadFromSessionCache( event, keyToLoad, options );
if ( entity == REMOVED_ENTITY_MARKER ) {
log.debug( "load request found matching entity in context, but it is scheduled for removal; returning null" );
return null;
}
+ if ( entity == INCONSISTENT_RTN_CLASS_MARKER ) {
+ log.debug( "load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null" );
+ return null;
+ }
if ( entity != null ) {
if ( log.isTraceEnabled() ) {
log.trace(
@@ -346,13 +354,6 @@
return entity;
}
- // Entity not found in session; before going any further, see if we
- // already determined that this entity does not exist
- /*if ( event.getSession().getPersistenceContext().isNonExistant(keyToLoad) ) {
- if ( log.isTraceEnabled() ) log.trace("entity does not exist");
- return null;
- }*/
-
entity = loadFromSecondLevelCache(event, persister, options);
if ( entity != null ) {
if ( log.isTraceEnabled() ) {
@@ -378,30 +379,26 @@
* Performs the process of loading an entity from the configured
* underlying datasource.
*
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
* @return The object loaded from the datasource, or null if not found.
* @throws HibernateException
*/
protected Object loadFromDatasource(
- final LoadEvent event,
- final EntityPersister persister,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
-
+ final LoadEvent event,
+ final EntityPersister persister,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
final SessionImplementor source = event.getSession();
-
Object entity = persister.load(
- event.getEntityId(),
- event.getInstanceToLoad(),
- event.getLockMode(),
+ event.getEntityId(),
+ event.getInstanceToLoad(),
+ event.getLockMode(),
source
- );
-
- /*if ( entity == null ) {
- //remember it doesn't exist, in case of next time
- source.getPersistenceContext().addNonExistantEntityKey(keyToLoad);
- }*/
-
+ );
+
if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
}
@@ -410,22 +407,30 @@
}
/**
- * Attempts to locate the entity in the session-level cache. If
- * checkDeleted was set to true, then if the entity is found in the
+ * Attempts to locate the entity in the session-level cache.
+ * <p/>
+ * If allowed to return nulls, then if the entity happens to be found in
+ * the session cache, we check the entity type for proper handling
+ * of entity hierarchies.
+ * <p/>
+ * If checkDeleted was set to true, then if the entity is found in the
* session-level cache, it's current status within the session cache
* is checked to see if it has previously been scheduled for deletion.
*
+ * @param event The load event
+ * @param keyToLoad The EntityKey representing the entity to be loaded.
+ * @param options The load options.
* @return The entity from the session-level cache, or null.
- * @throws HibernateException
+ * @throws HibernateException Generally indicates problems applying a lock-mode.
*/
protected Object loadFromSessionCache(
- final LoadEvent event,
- final EntityKey keyToLoad,
- final LoadEventListener.LoadType options)
- throws HibernateException {
-
+ final LoadEvent event,
+ final EntityKey keyToLoad,
+ final LoadEventListener.LoadType options) throws HibernateException {
+
SessionImplementor session = event.getSession();
Object old = session.getEntityUsingInterceptor( keyToLoad );
+
if ( old != null ) {
// this object was already loaded
EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
@@ -435,52 +440,61 @@
return REMOVED_ENTITY_MARKER;
}
}
+ if ( options.isAllowNulls() ) {
+ EntityPersister persister = event.getSession().getFactory().getEntityPersister( event.getEntityClassName() );
+ if ( ! persister.isInstance( old, event.getSession().getEntityMode() ) ) {
+ return INCONSISTENT_RTN_CLASS_MARKER;
+ }
+ }
upgradeLock( old, oldEntry, event.getLockMode(), session );
}
+
return old;
}
/**
* Attempts to load the entity from the second-level cache.
*
+ * @param event The load event
+ * @param persister The persister for the entity being requested for load
+ * @param options The load options.
* @return The entity from the second-level cache, or null.
* @throws HibernateException
*/
protected Object loadFromSecondLevelCache(
- final LoadEvent event,
- final EntityPersister persister,
- final LoadEventListener.LoadType options)
- throws HibernateException {
-
+ final LoadEvent event,
+ final EntityPersister persister,
+ final LoadEventListener.LoadType options) throws HibernateException {
+
final SessionImplementor source = event.getSession();
-
- final boolean useCache = persister.hasCache() &&
- source.getCacheMode().isGetEnabled() &&
+
+ final boolean useCache = persister.hasCache() &&
+ source.getCacheMode().isGetEnabled() &&
event.getLockMode().lessThan(LockMode.READ);
-
+
if (useCache) {
-
+
final SessionFactoryImplementor factory = source.getFactory();
-
- final CacheKey ck = new CacheKey(
- event.getEntityId(),
- persister.getIdentifierType(),
+
+ final CacheKey ck = new CacheKey(
+ event.getEntityId(),
+ persister.getIdentifierType(),
persister.getRootEntityName(),
- source.getEntityMode(),
+ source.getEntityMode(),
source.getFactory()
);
Object ce = persister.getCache()
.get( ck, source.getTimestamp() );
-
+
if ( factory.getStatistics().isStatisticsEnabled() ) {
if (ce==null) {
- factory.getStatisticsImplementor().secondLevelCacheMiss(
- persister.getCache().getRegionName()
+ factory.getStatisticsImplementor().secondLevelCacheMiss(
+ persister.getCache().getRegionName()
);
}
else {
- factory.getStatisticsImplementor().secondLevelCacheHit(
- persister.getCache().getRegionName()
+ factory.getStatisticsImplementor().secondLevelCacheHit(
+ persister.getCache().getRegionName()
);
}
}
@@ -489,7 +503,7 @@
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure()
.destructure(ce, factory);
-
+
// Entity was found in second-level cache...
return assembleCacheEntry(
entry,
@@ -499,21 +513,20 @@
);
}
}
-
+
return null;
}
private Object assembleCacheEntry(
- final CacheEntry entry,
- final Serializable id,
- final EntityPersister persister,
- final LoadEvent event)
- throws HibernateException {
-
+ final CacheEntry entry,
+ final Serializable id,
+ final EntityPersister persister,
+ final LoadEvent event) throws HibernateException {
+
final Object optionalObject = event.getInstanceToLoad();
final EventSource session = event.getSession();
final SessionFactoryImplementor factory = session.getFactory();
-
+
if ( log.isTraceEnabled() ) {
log.trace(
"assembling entity from second-level cache: " +
@@ -522,15 +535,15 @@
}
EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
- Object result = optionalObject == null ?
+ Object result = optionalObject == null ?
session.instantiate( subclassPersister, id ) : optionalObject;
-
+
// make it circular-reference safe
- TwoPhaseLoad.addUninitializedCachedEntity(
- new EntityKey( id, subclassPersister, session.getEntityMode() ),
- result,
- subclassPersister,
- LockMode.NONE,
+ TwoPhaseLoad.addUninitializedCachedEntity(
+ new EntityKey( id, subclassPersister, session.getEntityMode() ),
+ result,
+ subclassPersister,
+ LockMode.NONE,
entry.areLazyPropertiesUnfetched(),
entry.getVersion(),
session
@@ -538,30 +551,30 @@
Type[] types = subclassPersister.getPropertyTypes();
Object[] values = entry.assemble( result, id, subclassPersister, session.getInterceptor(), session ); // intializes result by side-effect
- TypeFactory.deepCopy(
- values,
- types,
- subclassPersister.getPropertyUpdateability(),
- values,
+ TypeFactory.deepCopy(
+ values,
+ types,
+ subclassPersister.getPropertyUpdateability(),
+ values,
session
);
-
+
Object version = Versioning.getVersion( values, subclassPersister );
if ( log.isTraceEnabled() ) log.trace( "Cached Version: " + version );
-
+
final PersistenceContext persistenceContext = session.getPersistenceContext();
- persistenceContext.addEntry(
- result,
- Status.MANAGED,
- values,
- null,
- id,
- version,
- LockMode.NONE,
- true,
- subclassPersister,
- false,
- entry.areLazyPropertiesUnfetched()
+ persistenceContext.addEntry(
+ result,
+ Status.MANAGED,
+ values,
+ null,
+ id,
+ version,
+ LockMode.NONE,
+ true,
+ subclassPersister,
+ false,
+ entry.areLazyPropertiesUnfetched()
);
subclassPersister.afterInitialize( result, entry.areLazyPropertiesUnfetched(), session );
persistenceContext.initializeNonLazyCollections();
@@ -576,7 +589,7 @@
for ( int i = 0; i < listeners.length; i++ ) {
listeners[i].onPostLoad(postLoadEvent);
}
-
+
return result;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java 2006-11-13 18:47:46 UTC (rev 10794)
+++ trunk/Hibernate3/test/org/hibernate/test/discriminator/DiscriminatorTest.java 2006-11-13 18:52:33 UTC (rev 10795)
@@ -3,6 +3,7 @@
import java.util.Iterator;
import java.util.List;
+import java.math.BigDecimal;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -10,21 +11,22 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.criterion.Property;
import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
public class DiscriminatorTest extends TestCase {
-
+
public DiscriminatorTest(String str) {
super(str);
}
-
- public void testJoinedSubclass() {
+
+ public void testDiscriminatorSubclass() {
Session s = openSession();
Transaction t = s.beginTransaction();
-
+
Employee mark = new Employee();
mark.setName("Mark");
mark.setTitle("internal sales");
@@ -32,7 +34,7 @@
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
-
+
Customer joe = new Customer();
joe.setName("Joe");
joe.setAddress("San Francisco");
@@ -41,17 +43,17 @@
joe.setComments("Very demanding");
joe.setSex('M');
joe.setSalesperson(mark);
-
+
Person yomomma = new Person();
yomomma.setName("mum");
yomomma.setSex('F');
-
+
s.save(yomomma);
s.save(mark);
s.save(joe);
-
+
assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
-
+
assertEquals( s.createQuery("from Person").list().size(), 3 );
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
@@ -65,7 +67,7 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
customers = s.createQuery("from Customer").list();
for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
Customer c = (Customer) iter.next();
@@ -74,11 +76,11 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
-
+
mark.setZip("30306");
assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
s.delete(mark);
@@ -89,7 +91,79 @@
s.close();
}
-
+ public void testAccessAsIncorrectSubclass() {
+ Session s = openSession();
+ s.beginTransaction();
+ Employee e = new Employee();
+ e.setName( "Steve" );
+ e.setSex( 'M' );
+ e.setTitle( "grand poobah" );
+ s.save( e );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Customer c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ e = ( Employee ) s.get( Employee.class, new Long( e.getId() ) );
+ c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNotNull( e );
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testQuerySubclassAttribute() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.setName("Emmanuel");
+ p.setSex('M');
+ s.persist(p);
+ Employee q = new Employee();
+ q.setName("Steve");
+ q.setSex('M');
+ q.setTitle("Mr");
+ q.setSalary( new BigDecimal(1000) );
+ s.persist(q);
+
+ List result = s.createQuery("from Person where salary > 100").list();
+ assertEquals( result.size(), 1 );
+ assertSame( result.get(0), q );
+
+ result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
+ assertEquals( result.size(), 2 );
+
+ result = s.createCriteria(Person.class)
+ .add( Property.forName("salary").gt( new BigDecimal(100) ) )
+ .list();
+ assertEquals( result.size(), 1 );
+ assertSame( result.get(0), q );
+
+ //TODO: make this work:
+ /*result = s.createQuery("select salary from Person where salary > 100").list();
+ assertEquals( result.size(), 1 );
+ assertEquals( result.get(0), new BigDecimal(1000) );*/
+
+ s.delete(p);
+ s.delete(q);
+ t.commit();
+ s.close();
+ }
+
+
protected String[] getMappings() {
return new String[] { "discriminator/Person.hbm.xml" };
}
Modified: trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-11-13 18:47:46 UTC (rev 10794)
+++ trunk/Hibernate3/test/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java 2006-11-13 18:52:33 UTC (rev 10795)
@@ -14,25 +14,21 @@
import org.hibernate.LockMode;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Property;
-import org.hibernate.dialect.DB2Dialect;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
public class JoinedSubclassTest extends TestCase {
-
+
public JoinedSubclassTest(String str) {
super(str);
}
-
+
public void testJoinedSubclass() {
Session s = openSession();
Transaction t = s.beginTransaction();
-
+
Employee mark = new Employee();
mark.setName("Mark");
mark.setTitle("internal sales");
@@ -40,7 +36,7 @@
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
-
+
Customer joe = new Customer();
joe.setName("Joe");
joe.setAddress("San Francisco");
@@ -49,17 +45,17 @@
joe.setComments("Very demanding");
joe.setSex('M');
joe.setSalesperson(mark);
-
+
Person yomomma = new Person();
yomomma.setName("mum");
yomomma.setSex('F');
-
+
s.save(yomomma);
s.save(mark);
s.save(joe);
-
+
assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
-
+
assertEquals( s.createQuery("from Person").list().size(), 3 );
assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
@@ -73,7 +69,7 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
customers = s.createQuery("from Customer").list();
for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
Customer c = (Customer) iter.next();
@@ -82,20 +78,20 @@
}
assertEquals( customers.size(), 1 );
s.clear();
-
+
mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
-
+
mark.setZip("30306");
assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
- if ( ! supportsRowValueConstructorSyntaxInInList() ) {
- s.createCriteria(Person.class).add(
- Expression.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )
+ if ( supportsRowValueConstructorSyntaxInInList() ) {
+ s.createCriteria(Person.class).add(
+ Expression.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )
).list();
}
-
+
s.delete(mark);
s.delete(joe);
s.delete(yomomma);
@@ -103,7 +99,41 @@
t.commit();
s.close();
}
-
+
+ public void testAccessAsIncorrectSubclass() {
+ Session s = openSession();
+ s.beginTransaction();
+ Employee e = new Employee();
+ e.setName( "Steve" );
+ e.setSex( 'M' );
+ e.setTitle( "grand poobah" );
+ s.save( e );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Customer c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ e = ( Employee ) s.get( Employee.class, new Long( e.getId() ) );
+ c = ( Customer ) s.get( Customer.class, new Long( e.getId() ) );
+ s.getTransaction().commit();
+ s.close();
+ assertNotNull( e );
+ assertNull( c );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e );
+ s.getTransaction().commit();
+ s.close();
+ }
+
public void testQuerySubclassAttribute() {
Session s = openSession();
Transaction t = s.beginTransaction();
@@ -121,9 +151,9 @@
List result = s.createQuery("from Person where salary > 100").list();
assertEquals( result.size(), 1 );
assertSame( result.get(0), q );
-
+
result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
- assertEquals( result.size(), 2 );
+ assertEquals( result.size(), 2 );
result = s.createCriteria(Person.class)
.add( Property.forName("salary").gt( new BigDecimal(100) ) )
@@ -135,7 +165,7 @@
/*result = s.createQuery("select salary from Person where salary > 100").list();
assertEquals( result.size(), 1 );
assertEquals( result.get(0), new BigDecimal(1000) );*/
-
+
s.delete(p);
s.delete(q);
t.commit();
@@ -168,7 +198,8 @@
s.close();
}
-
+
+
protected String[] getMappings() {
return new String[] { "joinedsubclass/Person.hbm.xml" };
}
17 years, 5 months
Hibernate SVN: r10794 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/dialect test/org/hibernate/test/dialect/cache
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 13:47:46 -0500 (Mon, 13 Nov 2006)
New Revision: 10794
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java
Log:
more minor InterSystems stuff
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-11-13 18:47:32 UTC (rev 10793)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-11-13 18:47:46 UTC (rev 10794)
@@ -1,4 +1,4 @@
-//$Id: $
+//$Id: $
package org.hibernate.dialect;
import java.sql.CallableStatement;
@@ -107,12 +107,10 @@
* <tr>
* <td>hibernate.connection.username</td>
* <td>(see note 1)</td>
- * <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.password</td>
* <td>(see note 1)</td>
- * <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.url</td>
@@ -151,17 +149,19 @@
* <p/>
* To use Hibernate sequence support with Caché in a namespace, you must FIRST load the following file into that namespace:
* <pre>
- * src\org\hibernate\dialect\CacheSequences.xml
+ * etc\CacheSequences.xml
* </pre>
+ * For example, at the COS terminal prompt in the namespace, run the
+ * following command:
+ * <p>
+ * d LoadFile^%apiOBJ("c:\hibernate\etc\CacheSequences.xml","ck")
+ * <p>
* In your Hibernate mapping you can specify sequence use.
* <p>
* For example, the following shows the use of a sequence generator in a Hibernate mapping:
* <pre>
* <id name="id" column="uid" type="long" unsaved-value="null">
- * <generator class="seqhilo">
- * <param name="sequence">EVENTS_SEQ</param>
- * <param name="max_lo">0</param>
- * </generator>
+ * <generator class="sequence"/>
* </id>
* </pre>
* <br>
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java 2006-11-13 18:47:32 UTC (rev 10793)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java 2006-11-13 18:47:46 UTC (rev 10794)
@@ -31,7 +31,7 @@
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.test.TestCase;
+import org.hibernate.test.DatabaseSpecificTestCase;
import org.hibernate.test.legacy.Simple;
import org.hibernate.test.legacy.Single;
import org.hibernate.test.legacy.Broken;
@@ -43,7 +43,7 @@
*
* @author Jonathan Levinson
*/
-public class SQLFunctionsInterSystemsTest extends TestCase {
+public class SQLFunctionsInterSystemsTest extends DatabaseSpecificTestCase {
private static final Log log = LogFactory.getLog(SQLFunctionsInterSystemsTest.class);
@@ -56,7 +56,7 @@
"legacy/AltSimple.hbm.xml",
"legacy/Broken.hbm.xml",
"legacy/Blobber.hbm.xml",
- "legacy/TestInterSystemsFunctionsClass.hbm.xml"
+ "dialect/cache/TestInterSystemsFunctionsClass.hbm.xml"
};
}
17 years, 5 months
Hibernate SVN: r10793 - in trunk/Hibernate3: src/org/hibernate/dialect test/org/hibernate/test/dialect/cache
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 13:47:32 -0500 (Mon, 13 Nov 2006)
New Revision: 10793
Modified:
trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
trunk/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java
Log:
more minor InterSystems stuff
Modified: trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-11-13 17:49:36 UTC (rev 10792)
+++ trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-11-13 18:47:32 UTC (rev 10793)
@@ -1,4 +1,4 @@
-//$Id: $
+//$Id: $
package org.hibernate.dialect;
import java.sql.CallableStatement;
@@ -107,12 +107,10 @@
* <tr>
* <td>hibernate.connection.username</td>
* <td>(see note 1)</td>
- * <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.password</td>
* <td>(see note 1)</td>
- * <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.url</td>
@@ -151,17 +149,19 @@
* <p/>
* To use Hibernate sequence support with Caché in a namespace, you must FIRST load the following file into that namespace:
* <pre>
- * src\org\hibernate\dialect\CacheSequences.xml
+ * etc\CacheSequences.xml
* </pre>
+ * For example, at the COS terminal prompt in the namespace, run the
+ * following command:
+ * <p>
+ * d LoadFile^%apiOBJ("c:\hibernate\etc\CacheSequences.xml","ck")
+ * <p>
* In your Hibernate mapping you can specify sequence use.
* <p>
* For example, the following shows the use of a sequence generator in a Hibernate mapping:
* <pre>
* <id name="id" column="uid" type="long" unsaved-value="null">
- * <generator class="seqhilo">
- * <param name="sequence">EVENTS_SEQ</param>
- * <param name="max_lo">0</param>
- * </generator>
+ * <generator class="sequence"/>
* </id>
* </pre>
* <br>
Modified: trunk/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java 2006-11-13 17:49:36 UTC (rev 10792)
+++ trunk/Hibernate3/test/org/hibernate/test/dialect/cache/SQLFunctionsInterSystemsTest.java 2006-11-13 18:47:32 UTC (rev 10793)
@@ -31,7 +31,7 @@
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.test.TestCase;
+import org.hibernate.test.DatabaseSpecificTestCase;
import org.hibernate.test.legacy.Simple;
import org.hibernate.test.legacy.Single;
import org.hibernate.test.legacy.Broken;
@@ -43,7 +43,7 @@
*
* @author Jonathan Levinson
*/
-public class SQLFunctionsInterSystemsTest extends TestCase {
+public class SQLFunctionsInterSystemsTest extends DatabaseSpecificTestCase {
private static final Log log = LogFactory.getLog(SQLFunctionsInterSystemsTest.class);
@@ -56,7 +56,7 @@
"legacy/AltSimple.hbm.xml",
"legacy/Broken.hbm.xml",
"legacy/Blobber.hbm.xml",
- "legacy/TestInterSystemsFunctionsClass.hbm.xml"
+ "dialect/cache/TestInterSystemsFunctionsClass.hbm.xml"
};
}
17 years, 5 months