Hibernate SVN: r11060 - in trunk/Hibernate3: src/org/hibernate/id and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-01-19 07:51:31 -0500 (Fri, 19 Jan 2007)
New Revision: 11060
Added:
trunk/Hibernate3/src/org/hibernate/engine/ValueInclusion.java
trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.java
trunk/Hibernate3/test/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java
Modified:
trunk/Hibernate3/src/org/hibernate/id/SelectGenerator.java
trunk/Hibernate3/src/org/hibernate/mapping/PropertyGeneration.java
trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java
trunk/Hibernate3/test/org/hibernate/test/generated/GeneratedPropertySuite.java
trunk/Hibernate3/test/org/hibernate/test/legacy/CustomPersister.java
Log:
HHH-1471 : components + partial generation
Added: trunk/Hibernate3/src/org/hibernate/engine/ValueInclusion.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/ValueInclusion.java (rev 0)
+++ trunk/Hibernate3/src/org/hibernate/engine/ValueInclusion.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -0,0 +1,51 @@
+package org.hibernate.engine;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.io.StreamCorruptedException;
+
+/**
+ * An enum of the different ways a value might be "included".
+ * <p/>
+ * This is really an expanded true/false notion with "PARTIAL" being the
+ * expansion. PARTIAL deals with components in the cases where
+ * parts of the referenced component might define inclusion, but the
+ * component overall does not.
+ *
+ * @author Steve Ebersole
+ */
+public class ValueInclusion implements Serializable {
+
+ public static final ValueInclusion NONE = new ValueInclusion( "none" );
+ public static final ValueInclusion FULL = new ValueInclusion( "full" );
+ public static final ValueInclusion PARTIAL = new ValueInclusion( "partial" );
+
+ private final String name;
+
+ public ValueInclusion(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return "ValueInclusion[" + name + "]";
+ }
+
+ private Object readResolve() throws ObjectStreamException {
+ if ( name.equals( NONE.name ) ) {
+ return NONE;
+ }
+ else if ( name.equals( FULL.name ) ) {
+ return FULL;
+ }
+ else if ( name.equals( PARTIAL.name ) ) {
+ return PARTIAL;
+ }
+ else {
+ throw new StreamCorruptedException( "unrecognized value inclusion [" + name + "]" );
+ }
+ }
+}
Modified: trunk/Hibernate3/src/org/hibernate/id/SelectGenerator.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/id/SelectGenerator.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/src/org/hibernate/id/SelectGenerator.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -14,6 +14,7 @@
import org.hibernate.id.insert.AbstractSelectingDelegate;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.ValueInclusion;
import org.hibernate.type.Type;
/**
@@ -57,7 +58,8 @@
"natural-id properties; need to specify [key] in generator parameters"
);
}
- if ( persister.getPropertyInsertGeneration() [ naturalIdPropertyIndices[0] ] ) {
+ ValueInclusion inclusion = persister.getPropertyInsertGenerationInclusions() [ naturalIdPropertyIndices[0] ];
+ if ( inclusion != ValueInclusion.NONE ) {
throw new IdentifierGenerationException(
"natural-id also defined as insert-generated; need to specify [key] " +
"in generator parameters"
Modified: trunk/Hibernate3/src/org/hibernate/mapping/PropertyGeneration.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/PropertyGeneration.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/src/org/hibernate/mapping/PropertyGeneration.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -6,7 +6,7 @@
* Indicates whether given properties are generated by the database and, if
* so, at what time(s) they are generated.
*
- * @author <a href="mailto:steve@hibernate.org">Steve Ebersole </a>
+ * @author Steve Ebersole
*/
public class PropertyGeneration implements Serializable {
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -44,6 +44,7 @@
import org.hibernate.engine.Versioning;
import org.hibernate.engine.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.EntityKey;
+import org.hibernate.engine.ValueInclusion;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.PostInsertIdentifierGenerator;
@@ -301,9 +302,7 @@
}
String[] result = new String[getTableSpan()];
result[0] = sqlUpdateByRowIdString;
- for ( int i = 1; i < getTableSpan(); i++ ) {
- result[i] = sqlUpdateStrings[i];
- }
+ System.arraycopy( sqlUpdateStrings, 1, result, 1, getTableSpan() );
return result;
}
@@ -345,6 +344,8 @@
/**
* The query that inserts a row, letting the database generate an id
+ *
+ * @return The IDENTITY-based insertion query.
*/
protected String getSQLIdentityInsertString() {
return sqlIdentityInsertString;
@@ -379,7 +380,15 @@
}
/**
- * Decide which tables need to be updated
+ * Decide which tables need to be updated.
+ * <p/>
+ * The return here is an array of boolean values with each index corresponding
+ * to a given table in the scope of this persister.
+ *
+ * @param dirtyProperties The indices of all the entity properties considered dirty.
+ * @param hasDirtyCollection Whether any collections owned by the entity which were considered dirty.
+ *
+ * @return Array of booleans indicating which table require updating.
*/
protected boolean[] getTableUpdateNeeded(final int[] dirtyProperties, boolean hasDirtyCollection) {
@@ -583,8 +592,8 @@
names.add( prop.getName() );
classes.add( prop.getPersistentClass().getEntityName() );
boolean isDefinedBySubclass = !thisClassProperties.contains( prop );
- definedBySubclass.add( new Boolean(isDefinedBySubclass) );
- propNullables.add( new Boolean( prop.isOptional() || isDefinedBySubclass) ); //TODO: is this completely correct?
+ definedBySubclass.add( Boolean.valueOf( isDefinedBySubclass ) );
+ propNullables.add( Boolean.valueOf( prop.isOptional() || isDefinedBySubclass ) ); //TODO: is this completely correct?
types.add( prop.getType() );
Iterator colIter = prop.getColumnIterator();
@@ -593,7 +602,7 @@
int[] colnos = new int[prop.getColumnSpan()];
int[] formnos = new int[prop.getColumnSpan()];
int l = 0;
- Boolean lazy = new Boolean( prop.isLazy() && lazyAvailable );
+ Boolean lazy = Boolean.valueOf( prop.isLazy() && lazyAvailable );
while ( colIter.hasNext() ) {
Selectable thing = ( Selectable ) colIter.next();
if ( thing.isFormula() ) {
@@ -614,7 +623,7 @@
cols[l] = colName;
aliases.add( thing.getAlias( factory.getDialect(), prop.getValue().getTable() ) );
columnsLazy.add( lazy );
- columnSelectables.add( new Boolean( prop.isSelectable() ) );
+ columnSelectables.add( Boolean.valueOf( prop.isSelectable() ) );
}
l++;
}
@@ -1066,14 +1075,14 @@
}
protected String generateInsertGeneratedValuesSelectString() {
- return generateGeneratedValuesSelectString( getPropertyInsertGeneration() );
+ return generateGeneratedValuesSelectString( getPropertyInsertGenerationInclusions() );
}
protected String generateUpdateGeneratedValuesSelectString() {
- return generateGeneratedValuesSelectString( getPropertyUpdateGeneration() );
+ return generateGeneratedValuesSelectString( getPropertyUpdateGenerationInclusions() );
}
- private String generateGeneratedValuesSelectString(boolean[] inclusions) {
+ private String generateGeneratedValuesSelectString(ValueInclusion[] inclusions) {
Select select = new Select( getFactory().getDialect() );
if ( getFactory().getSettings().isCommentsEnabled() ) {
@@ -1082,6 +1091,9 @@
String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );
+ // Here we render the select column list based on the properties defined as being generated.
+ // For partial component generation, we currently just re-select the whole component
+ // rather than trying to handle the individual generated portions.
String selectClause = concretePropertySelectFragment( getRootAlias(), inclusions );
selectClause = selectClause.substring( 2 );
@@ -1101,22 +1113,52 @@
.toStatementString();
}
- protected String concretePropertySelectFragment(String alias, boolean[] includeProperty) {
+ protected static interface InclusionChecker {
+ public boolean includeProperty(int propertyNumber);
+ }
+
+ protected String concretePropertySelectFragment(String alias, final ValueInclusion[] inclusions) {
+ return concretePropertySelectFragment(
+ alias,
+ new InclusionChecker() {
+ // TODO : currently we really do not handle ValueInclusion.PARTIAL...
+ // ValueInclusion.PARTIAL would indicate parts of a component need to
+ // be included in the select; currently we then just render the entire
+ // component into the select clause in that case.
+ public boolean includeProperty(int propertyNumber) {
+ return inclusions[propertyNumber] != ValueInclusion.NONE;
+ }
+ }
+ );
+ }
+
+ protected String concretePropertySelectFragment(String alias, final boolean[] includeProperty) {
+ return concretePropertySelectFragment(
+ alias,
+ new InclusionChecker() {
+ public boolean includeProperty(int propertyNumber) {
+ return includeProperty[propertyNumber];
+ }
+ }
+ );
+ }
+
+ protected String concretePropertySelectFragment(String alias, InclusionChecker inclusionChecker) {
int propertyCount = getPropertyNames().length;
int[] propertyTableNumbers = getPropertyTableNumbersInSelect();
SelectFragment frag = new SelectFragment();
for ( int i = 0; i < propertyCount; i++ ) {
- if ( includeProperty[i] ) { //ie. updateable, not a formula
+ if ( inclusionChecker.includeProperty( i ) ) {
frag.addColumns(
generateTableAlias( alias, propertyTableNumbers[i] ),
propertyColumnNames[i],
propertyColumnAliases[i]
- );
+ );
frag.addFormulas(
generateTableAlias( alias, propertyTableNumbers[i] ),
propertyColumnFormulaTemplates[i],
propertyColumnAliases[i]
- );
+ );
}
}
return frag.toFragmentString();
@@ -1810,9 +1852,8 @@
}
private boolean checkVersion(final boolean[] includeProperty) {
- boolean checkVersion = includeProperty[ getVersionProperty() ] ||
- entityMetamodel.getPropertyUpdateGeneration()[ getVersionProperty() ];
- return checkVersion;
+ return includeProperty[ getVersionProperty() ] ||
+ entityMetamodel.getPropertyUpdateGenerationInclusions()[ getVersionProperty() ] != ValueInclusion.NONE;
}
protected String generateInsertString(boolean[] includeProperty, int j) {
@@ -3430,15 +3471,15 @@
}
public boolean hasInsertGeneratedProperties() {
- return !ArrayHelper.isAllFalse( getPropertyInsertGeneration() );
+ return entityMetamodel.hasInsertGeneratedValues();
}
public boolean hasUpdateGeneratedProperties() {
- return !ArrayHelper.isAllFalse( getPropertyUpdateGeneration() );
+ return entityMetamodel.hasUpdateGeneratedValues();
}
public boolean isVersionPropertyGenerated() {
- return isVersioned() && getPropertyUpdateGeneration() [ getVersionProperty() ];
+ return isVersioned() && ( getPropertyUpdateGenerationInclusions() [ getVersionProperty() ] != ValueInclusion.NONE );
}
public boolean isVersionPropertyInsertable() {
@@ -3477,12 +3518,12 @@
return entityMetamodel.getPropertyInsertability();
}
- public boolean[] getPropertyInsertGeneration() {
- return entityMetamodel.getPropertyInsertGeneration();
+ public ValueInclusion[] getPropertyInsertGenerationInclusions() {
+ return entityMetamodel.getPropertyInsertGenerationInclusions();
}
- public boolean[] getPropertyUpdateGeneration() {
- return entityMetamodel.getPropertyUpdateGeneration();
+ public ValueInclusion[] getPropertyUpdateGenerationInclusions() {
+ return entityMetamodel.getPropertyUpdateGenerationInclusions();
}
public boolean[] getPropertyNullability() {
@@ -3625,14 +3666,14 @@
if ( !hasInsertGeneratedProperties() ) {
throw new AssertionFailure("no insert-generated properties");
}
- processGeneratedProperties( id, entity, state, session, sqlInsertGeneratedValuesSelectString, getPropertyInsertGeneration() );
+ processGeneratedProperties( id, entity, state, session, sqlInsertGeneratedValuesSelectString, getPropertyInsertGenerationInclusions() );
}
public void processUpdateGeneratedProperties(Serializable id, Object entity, Object[] state, SessionImplementor session) {
if ( !hasInsertGeneratedProperties() ) {
throw new AssertionFailure("no update-generated properties");
}
- processGeneratedProperties( id, entity, state, session, sqlUpdateGeneratedValuesSelectString, getPropertyUpdateGeneration() );
+ processGeneratedProperties( id, entity, state, session, sqlUpdateGeneratedValuesSelectString, getPropertyUpdateGenerationInclusions() );
}
private void processGeneratedProperties(
@@ -3641,7 +3682,7 @@
Object[] state,
SessionImplementor session,
String selectionSQL,
- boolean[] included ) {
+ ValueInclusion[] includeds) {
session.getBatcher().executeBatch(); //force immediate execution of the insert
@@ -3658,8 +3699,9 @@
);
}
for ( int i = 0; i < getPropertySpan(); i++ ) {
- if ( included[i] ) {
- state[i] = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
+ if ( includeds[i] != ValueInclusion.NONE ) {
+ Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
+ state[i] = getPropertyTypes()[i].resolve( hydratedState, session, entity );
setPropertyValue( entity, i, state[i], session.getEntityMode() );
}
}
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -15,6 +15,7 @@
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.Type;
@@ -361,12 +362,12 @@
/**
* Which of the properties of this class are database generated values on insert?
*/
- public boolean[] getPropertyInsertGeneration();
+ public ValueInclusion[] getPropertyInsertGenerationInclusions();
/**
* Which of the properties of this class are database generated values on update?
*/
- public boolean[] getPropertyUpdateGeneration();
+ public ValueInclusion[] getPropertyUpdateGenerationInclusions();
/**
* Get the "updateability" of the properties of this class
Modified: trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -23,9 +23,11 @@
import org.hibernate.engine.CascadeStyle;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.Versioning;
+import org.hibernate.engine.ValueInclusion;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.EntityType;
@@ -65,11 +67,13 @@
private final boolean[] nonlazyPropertyUpdateability;
private final boolean[] propertyCheckability;
private final boolean[] propertyInsertability;
- private final boolean[] propertyInsertGeneration;
- private final boolean[] propertyUpdateGeneration;
+ private final ValueInclusion[] insertInclusions;
+ private final ValueInclusion[] updateInclusions;
private final boolean[] propertyNullability;
private final boolean[] propertyVersionability;
private final CascadeStyle[] cascadeStyles;
+ private final boolean hasInsertGeneratedValues;
+ private final boolean hasUpdateGeneratedValues;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private final Map propertyIndexes = new HashMap();
private final boolean hasCollections;
@@ -135,8 +139,8 @@
propertyTypes = new Type[propertySpan];
propertyUpdateability = new boolean[propertySpan];
propertyInsertability = new boolean[propertySpan];
- propertyInsertGeneration = new boolean[propertySpan];
- propertyUpdateGeneration = new boolean[propertySpan];
+ insertInclusions = new ValueInclusion[propertySpan];
+ updateInclusions = new ValueInclusion[propertySpan];
nonlazyPropertyUpdateability = new boolean[propertySpan];
propertyCheckability = new boolean[propertySpan];
propertyNullability = new boolean[propertySpan];
@@ -153,6 +157,8 @@
boolean foundCollection = false;
boolean foundMutable = false;
boolean foundNonIdentifierPropertyNamedId = false;
+ boolean foundInsertGeneratedValue = false;
+ boolean foundUpdateGeneratedValue = false;
while ( iter.hasNext() ) {
Property prop = ( Property ) iter.next();
@@ -183,8 +189,8 @@
propertyNullability[i] = properties[i].isNullable();
propertyUpdateability[i] = properties[i].isUpdateable();
propertyInsertability[i] = properties[i].isInsertable();
- propertyInsertGeneration[i] = properties[i].isInsertGenerated();
- propertyUpdateGeneration[i] = properties[i].isUpdateGenerated();
+ insertInclusions[i] = determineInsertValueGenerationType( prop, properties[i] );
+ updateInclusions[i] = determineUpdateValueGenerationType( prop, properties[i] );
propertyVersionability[i] = properties[i].isVersionable();
nonlazyPropertyUpdateability[i] = properties[i].isUpdateable() && !lazy;
propertyCheckability[i] = propertyUpdateability[i] ||
@@ -209,6 +215,14 @@
foundMutable = true;
}
+ if ( insertInclusions[i] != ValueInclusion.NONE ) {
+ foundInsertGeneratedValue = true;
+ }
+
+ if ( updateInclusions[i] != ValueInclusion.NONE ) {
+ foundUpdateGeneratedValue = true;
+ }
+
mapPropertyToIndex(prop, i);
i++;
}
@@ -220,6 +234,9 @@
naturalIdPropertyNumbers = ArrayHelper.toIntArray(naturalIdNumbers);
}
+ hasInsertGeneratedValues = foundInsertGeneratedValue;
+ hasUpdateGeneratedValues = foundUpdateGeneratedValue;
+
hasCascades = foundCascade;
hasNonIdentifierPropertyNamedId = foundNonIdentifierPropertyNamedId;
versionPropertyIndex = tempVersionProperty;
@@ -232,7 +249,7 @@
// TODO: this disables laziness even in non-pojo entity modes:
!persistentClass.hasPojoRepresentation() ||
!ReflectHelper.isFinalClass( persistentClass.getProxyInterface() )
- );
+ );
mutable = persistentClass.isMutable();
if ( persistentClass.isAbstract() == null ) {
// legacy behavior (with no abstract attribute specified)
@@ -278,6 +295,62 @@
tuplizerMapping = new EntityEntityModeToTuplizerMapping( persistentClass, this );
}
+ private ValueInclusion determineInsertValueGenerationType(Property mappingProperty, StandardProperty runtimeProperty) {
+ if ( runtimeProperty.isInsertGenerated() ) {
+ return ValueInclusion.FULL;
+ }
+ else if ( mappingProperty.getValue() instanceof Component ) {
+ if ( hasPartialInsertComponentGeneration( ( Component ) mappingProperty.getValue() ) ) {
+ return ValueInclusion.PARTIAL;
+ }
+ }
+ return ValueInclusion.NONE;
+ }
+
+ private boolean hasPartialInsertComponentGeneration(Component component) {
+ Iterator subProperties = component.getPropertyIterator();
+ while ( subProperties.hasNext() ) {
+ Property prop = ( Property ) subProperties.next();
+ if ( prop.getGeneration() == PropertyGeneration.ALWAYS || prop.getGeneration() == PropertyGeneration.INSERT ) {
+ return true;
+ }
+ else if ( prop.getValue() instanceof Component ) {
+ if ( hasPartialInsertComponentGeneration( ( Component ) prop.getValue() ) ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private ValueInclusion determineUpdateValueGenerationType(Property mappingProperty, StandardProperty runtimeProperty) {
+ if ( runtimeProperty.isUpdateGenerated() ) {
+ return ValueInclusion.FULL;
+ }
+ else if ( mappingProperty.getValue() instanceof Component ) {
+ if ( hasPartialUpdateComponentGeneration( ( Component ) mappingProperty.getValue() ) ) {
+ return ValueInclusion.PARTIAL;
+ }
+ }
+ return ValueInclusion.NONE;
+ }
+
+ private boolean hasPartialUpdateComponentGeneration(Component component) {
+ Iterator subProperties = component.getPropertyIterator();
+ while ( subProperties.hasNext() ) {
+ Property prop = ( Property ) subProperties.next();
+ if ( prop.getGeneration() == PropertyGeneration.ALWAYS ) {
+ return true;
+ }
+ else if ( prop.getValue() instanceof Component ) {
+ if ( hasPartialUpdateComponentGeneration( ( Component ) prop.getValue() ) ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private void mapPropertyToIndex(Property prop, int i) {
propertyIndexes.put( prop.getName(), new Integer(i) );
if ( prop.getValue() instanceof Component ) {
@@ -481,12 +554,12 @@
return propertyInsertability;
}
- public boolean[] getPropertyInsertGeneration() {
- return propertyInsertGeneration;
+ public ValueInclusion[] getPropertyInsertGenerationInclusions() {
+ return insertInclusions;
}
- public boolean[] getPropertyUpdateGeneration() {
- return propertyUpdateGeneration;
+ public ValueInclusion[] getPropertyUpdateGenerationInclusions() {
+ return updateInclusions;
}
public boolean[] getPropertyNullability() {
@@ -500,5 +573,14 @@
public CascadeStyle[] getCascadeStyles() {
return cascadeStyles;
}
+
+ public boolean hasInsertGeneratedValues() {
+ return hasInsertGeneratedValues;
+ }
+
+ public boolean hasUpdateGeneratedValues() {
+ return hasUpdateGeneratedValues;
+ }
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
Added: trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.hbm.xml (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.hbm.xml 2007-01-19 12:51:31 UTC (rev 11060)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.generated">
+
+ <class name="ComponentOwner" table="part_gen_comp">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <property name="name" />
+ <component name="component" class="ComponentOwner$Component">
+ <property name="generated" type="int" generated="always" column="GENED"/>
+ </component>
+ </class>
+
+ <database-object>
+ <create>
+ <![CDATA[CREATE OR REPLACE TRIGGER t_iu_part_gen_comp
+ BEFORE INSERT OR UPDATE ON part_gen_comp
+ FOR EACH ROW
+ BEGIN
+ IF INSERTING THEN
+ :new.gened := 1;
+ ELSE
+ :new.gened := :old.gened + 1;
+ END IF;
+ END;]]>
+ </create>
+ <drop>
+ <![CDATA[DROP TRIGGER t_iu_part_gen_comp]]>
+ </drop>
+ <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
+ <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
+ </database-object>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/generated/ComponentOwner.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -0,0 +1,55 @@
+package org.hibernate.test.generated;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentOwner {
+ private Long id;
+ private String name;
+ private Component component;
+
+ public ComponentOwner() {
+ }
+
+ public ComponentOwner(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Component getComponent() {
+ return component;
+ }
+
+ public void setComponent(Component component) {
+ this.component = component;
+ }
+
+ public static class Component {
+ private int generated;
+
+ public int getGenerated() {
+ return generated;
+ }
+
+ public void setGenerated(int generated) {
+ this.generated = generated;
+ }
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/generated/GeneratedPropertySuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/generated/GeneratedPropertySuite.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/test/org/hibernate/test/generated/GeneratedPropertySuite.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -14,6 +14,7 @@
suite.addTest( TimestampGeneratedValuesWithCachingTest.suite() );
suite.addTest( TriggerGeneratedValuesWithCachingTest.suite() );
suite.addTest( TriggerGeneratedValuesWithoutCachingTest.suite() );
+ suite.addTest( PartiallyGeneratedComponentTest.suite() );
return suite;
}
}
Added: trunk/Hibernate3/test/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/generated/PartiallyGeneratedComponentTest.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -0,0 +1,64 @@
+package org.hibernate.test.generated;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PartiallyGeneratedComponentTest extends DatabaseSpecificFunctionalTestCase {
+ public PartiallyGeneratedComponentTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "generated/ComponentOwner.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( PartiallyGeneratedComponentTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return dialect instanceof Oracle9Dialect;
+ }
+
+ public void testPartialComponentGeneration() {
+ ComponentOwner owner = new ComponentOwner( "initial" );
+ Session s = openSession();
+ s.beginTransaction();
+ s.save( owner );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNotNull( "expecting insert value generation", owner.getComponent() );
+ int previousValue = owner.getComponent().getGenerated();
+ assertFalse( "expecting insert value generation", 0 == previousValue );
+
+ s = openSession();
+ s.beginTransaction();
+ owner = ( ComponentOwner ) s.get( ComponentOwner.class, owner.getId() );
+ assertEquals( "expecting insert value generation", previousValue, owner.getComponent().getGenerated() );
+ owner.setName( "subsequent" );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNotNull( owner.getComponent() );
+ previousValue = owner.getComponent().getGenerated();
+
+ s = openSession();
+ s.beginTransaction();
+ owner = ( ComponentOwner ) s.get( ComponentOwner.class, owner.getId() );
+ assertEquals( "expecting update value generation", previousValue, owner.getComponent().getGenerated() );
+ s.delete( owner );
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/CustomPersister.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/CustomPersister.java 2007-01-18 01:51:13 UTC (rev 11059)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/CustomPersister.java 2007-01-19 12:51:31 UTC (rev 11060)
@@ -21,6 +21,7 @@
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.TwoPhaseLoad;
+import org.hibernate.engine.ValueInclusion;
import org.hibernate.event.EventSource;
import org.hibernate.event.PostLoadEvent;
import org.hibernate.event.PreLoadEvent;
@@ -471,12 +472,12 @@
return MUTABILITY;
}
- public boolean[] getPropertyInsertGeneration() {
- return new boolean[0];
+ public ValueInclusion[] getPropertyInsertGenerationInclusions() {
+ return new ValueInclusion[0];
}
- public boolean[] getPropertyUpdateGeneration() {
- return new boolean[0];
+ public ValueInclusion[] getPropertyUpdateGenerationInclusions() {
+ return new ValueInclusion[0];
}
17 years, 7 months
Hibernate SVN: r11059 - branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/bytecode.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 20:51:13 -0500 (Wed, 17 Jan 2007)
New Revision: 11059
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/bytecode/ProxyBreakingTest.java
Log:
fix path in test
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/bytecode/ProxyBreakingTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/bytecode/ProxyBreakingTest.java 2007-01-18 01:43:00 UTC (rev 11058)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/bytecode/ProxyBreakingTest.java 2007-01-18 01:51:13 UTC (rev 11059)
@@ -41,7 +41,7 @@
protected String[] getXmlFiles() {
return new String[] {
- "annotations/bytecode/Hammer.hbm.xml"
+ "org/hibernate/test/annotations/bytecode/Hammer.hbm.xml"
};
}
17 years, 7 months
Hibernate SVN: r11058 - branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 20:43:00 -0500 (Wed, 17 Jan 2007)
New Revision: 11058
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Order.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLine.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLinePk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Product.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
ANN-492 tests
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java 2007-01-17 23:26:34 UTC (rev 11057)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java 2007-01-18 01:43:00 UTC (rev 11058)
@@ -8,6 +8,10 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.annotations.cid.OrderLine;
+import org.hibernate.test.annotations.cid.Order;
+import org.hibernate.test.annotations.cid.Product;
+import org.hibernate.test.annotations.cid.OrderLinePk;
/**
* test some composite id functionalities
@@ -93,13 +97,43 @@
s.close();
}
+ public void testManyToOneInCompositeIdClass() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Order order = new Order();
+ s.persist( order );
+ Product product = new Product();
+ product.name = "small car";
+ s.persist( product );
+ OrderLinePk pk = new OrderLinePk();
+ OrderLine orderLine = new OrderLine();
+ orderLine.order = order;
+ orderLine.product = product;
+ s.persist(orderLine);
+ s.flush();
+ s.clear();
+
+ orderLine = (OrderLine) s.createQuery( "select ol from OrderLine ol" ).uniqueResult();
+ assertNotNull( orderLine.order );
+ assertEquals( order.id, orderLine.order.id );
+ assertNotNull( orderLine.product );
+ assertEquals( product.name, orderLine.product.name );
+
+ tx.rollback();
+ s.close();
+ }
+
protected Class[] getMappings() {
return new Class[]{
Parent.class,
Child.class,
Channel.class,
TvMagazin.class,
- Presenter.class
- };
+ Presenter.class,
+ Order.class,
+ Product.class,
+ OrderLine.class,
+ OrderLinePk.class
+ };
}
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Order.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Order.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Order.java 2007-01-18 01:43:00 UTC (rev 11058)
@@ -0,0 +1,17 @@
+package org.hibernate.test.annotations.cid;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name = "OrderTableFoobar")
+public class Order {
+ @Id
+ @GeneratedValue
+ public Integer id;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLine.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLine.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLine.java 2007-01-18 01:43:00 UTC (rev 11058)
@@ -0,0 +1,17 @@
+package org.hibernate.test.annotations.cid;
+
+import javax.persistence.Entity;
+import javax.persistence.IdClass;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+(a)IdClass(OrderLinePk.class)
+public class OrderLine {
+ @Id
+ public Order order;
+ @Id
+ public Product product;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLinePk.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLinePk.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/OrderLinePk.java 2007-01-18 01:43:00 UTC (rev 11058)
@@ -0,0 +1,18 @@
+package org.hibernate.test.annotations.cid;
+
+
+import javax.persistence.ManyToOne;
+import javax.persistence.JoinColumn;
+import java.io.Serializable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class OrderLinePk implements Serializable {
+ @ManyToOne
+ @JoinColumn(name = "foo", nullable = false)
+ public Order order;
+ @ManyToOne
+ @JoinColumn(name = "bar", nullable = false)
+ public Product product;
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Product.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Product.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/cid/Product.java 2007-01-18 01:43:00 UTC (rev 11058)
@@ -0,0 +1,13 @@
+package org.hibernate.test.annotations.cid;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Product {
+ @Id
+ public String name;
+}
17 years, 7 months
Hibernate SVN: r11057 - in branches/Branch_3_2/HibernateExt/metadata/src: java/org/hibernate/validator and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 18:26:34 -0500 (Wed, 17 Jan 2007)
New Revision: 11057
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
Log:
ANN-502 skip validator.apply when apply_to_ddl = false
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-01-17 22:16:33 UTC (rev 11056)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-01-17 23:26:34 UTC (rev 11057)
@@ -310,17 +310,21 @@
buildUniqueKeyFromColumnNames( columnNames, table, keyName );
}
}
- for ( PersistentClass persistentClazz : (Collection<PersistentClass>) classes.values() ) {
- //integrate the validate framework
- String className = persistentClazz.getClassName();
- if ( StringHelper.isNotEmpty( className ) ) {
- try {
- new ClassValidator( ReflectHelper.classForName( className ), null, null, null, reflectionManager )
- .apply( persistentClazz );
+ boolean applyOnDdl = getProperties().getProperty( org.hibernate.validator.Environment.APPLY_TO_DDL, "true" )
+ .equalsIgnoreCase( "true" );
+ if (applyOnDdl) {
+ for ( PersistentClass persistentClazz : (Collection<PersistentClass>) classes.values() ) {
+ //integrate the validate framework
+ String className = persistentClazz.getClassName();
+ if ( StringHelper.isNotEmpty( className ) ) {
+ try {
+ new ClassValidator( ReflectHelper.classForName( className ), null, null, null, reflectionManager )
+ .apply( persistentClazz );
+ }
+ catch (ClassNotFoundException e) {
+ //swallow them
+ }
}
- catch (ClassNotFoundException e) {
- //swallow them
- }
}
}
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2007-01-17 22:16:33 UTC (rev 11056)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2007-01-17 23:26:34 UTC (rev 11057)
@@ -13,4 +13,9 @@
* Message interpolator class used. The same instance is shared across all ClassValidators
*/
public static final String MESSAGE_INTERPOLATOR_CLASS = "hibernate.validator.message_interpolator_class";
+
+ /**
+ * Apply DDL changes on Hibernate metamodel when using validator with Hibernate Annotations
+ */
+ public static final String APPLY_TO_DDL = "hibernate.validator.apply_to_ddl";
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-17 23:26:34 UTC (rev 11057)
@@ -0,0 +1,49 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Column;
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.event.ValidatePreInsertEventListener;
+import org.hibernate.validator.event.ValidatePreUpdateEventListener;
+
+/**
+ * Test the validate framework integration with the Hibernate
+ * metadata binding
+ *
+ * @author Emmanuel Bernard
+ */
+public class NonHibernateAnnotationsIntegrationTest extends TestCase {
+ public void testNotApply() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
+ //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
+ Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
+ assertFalse( stateColumn.getLength() == 3 );
+ Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
+ assertFalse( zipColumn.getLength() == 5 );
+ assertTrue( zipColumn.isNullable() );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
+ cfg.setProperty( Environment.APPLY_TO_DDL, "false" );
+ cfg.getEventListeners()
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
+ cfg.getEventListeners()
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidatePreUpdateEventListener()} );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Address.class,
+ };
+ }
+
+ public NonHibernateAnnotationsIntegrationTest(String x) {
+ super( x );
+ }
+}
17 years, 7 months
Hibernate SVN: r11056 - branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 17:16:33 -0500 (Wed, 17 Jan 2007)
New Revision: 11056
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Item.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ItemCost.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Vendor.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/WarehouseItem.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
Log:
ANN-509 more tests
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Item.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Item.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Item.java 2007-01-17 22:16:33 UTC (rev 11056)
@@ -0,0 +1,23 @@
+//$Id: $
+package org.hibernate.test.annotations.referencedcolumnname;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Item {
+ int id;
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ItemCost.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ItemCost.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ItemCost.java 2007-01-17 22:16:33 UTC (rev 11056)
@@ -0,0 +1,55 @@
+//$Id: $
+package org.hibernate.test.annotations.referencedcolumnname;
+
+import java.math.BigDecimal;
+import java.io.Serializable;
+import javax.persistence.Id;
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class ItemCost implements Serializable {
+ int id;
+ Item item;
+ Vendor vendor;
+ BigDecimal cost;
+
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @ManyToOne
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ @ManyToOne
+ public Vendor getVendor() {
+ return vendor;
+ }
+
+ public void setVendor(Vendor vendor) {
+ this.vendor = vendor;
+ }
+
+ public BigDecimal getCost() {
+ return cost;
+ }
+
+ public void setCost(BigDecimal cost) {
+ this.cost = cost;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2007-01-17 20:07:04 UTC (rev 11055)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2007-01-17 22:16:33 UTC (rev 11056)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.referencedcolumnname;
import java.util.Iterator;
+import java.math.BigDecimal;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -141,7 +142,36 @@
}
tx.commit();
s.close();
+ }
+ public void testManyToOneReferenceManyToOne() throws Exception {
+ Item item = new Item();
+ item.setId( 1 );
+ Vendor vendor = new Vendor();
+ vendor.setId( 1 );
+ ItemCost cost = new ItemCost();
+ cost.setCost( new BigDecimal(1) );
+ cost.setId( 1 );
+ cost.setItem( item );
+ cost.setVendor( vendor );
+ WarehouseItem wItem = new WarehouseItem();
+ wItem.setDefaultCost( cost );
+ wItem.setId( 1 );
+ wItem.setItem( item );
+ wItem.setQtyInStock( new BigDecimal(1) );
+ wItem.setVendor( vendor );
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.persist( item );
+ s.persist( vendor );
+ s.persist( cost );
+ s.persist( wItem );
+ s.flush();
+ s.clear();
+ wItem = (WarehouseItem) s.get(WarehouseItem.class, wItem.getId() );
+ assertNotNull( wItem.getDefaultCost().getItem() );
+ s.getTransaction().rollback();
+ s.close();
}
public ReferencedColumnNameTest(String x) {
@@ -156,7 +186,11 @@
Rambler.class,
Luggage.class,
Clothes.class,
- Inhabitant.class
+ Inhabitant.class,
+ Item.class,
+ ItemCost.class,
+ Vendor.class,
+ WarehouseItem.class
};
}
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Vendor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Vendor.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/Vendor.java 2007-01-17 22:16:33 UTC (rev 11056)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.test.annotations.referencedcolumnname;
+
+import javax.persistence.Id;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Vendor {
+ int id;
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
+
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/WarehouseItem.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/WarehouseItem.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/referencedcolumnname/WarehouseItem.java 2007-01-17 22:16:33 UTC (rev 11056)
@@ -0,0 +1,71 @@
+//$Id: $
+package org.hibernate.test.annotations.referencedcolumnname;
+
+import java.math.BigDecimal;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+import javax.persistence.JoinColumn;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class WarehouseItem {
+
+ int id;
+ Item item;
+ Vendor vendor;
+ ItemCost defaultCost;
+ BigDecimal qtyInStock;
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public BigDecimal getQtyInStock() {
+ return qtyInStock;
+ }
+
+ public void setQtyInStock(BigDecimal qtyInStock) {
+ this.qtyInStock = qtyInStock;
+ }
+
+ @ManyToOne
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ @ManyToOne
+ public Vendor getVendor() {
+ return vendor;
+ }
+
+ public void setVendor(Vendor vendor) {
+ this.vendor = vendor;
+ }
+
+ @ManyToOne
+ @JoinColumns({
+ @JoinColumn(name="vendor_id", referencedColumnName="vendor_id", insertable=false, updatable=false),
+ @JoinColumn(name="item_id", referencedColumnName="item_id", insertable=false, updatable=false)
+ })
+ public ItemCost getDefaultCost() {
+ return defaultCost;
+ }
+
+ public void setDefaultCost(ItemCost defaultCost) {
+ this.defaultCost = defaultCost;
+ }
+}
+
17 years, 7 months
Hibernate SVN: r11055 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/test/annotations/various and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 15:07:04 -0500 (Wed, 17 Jan 2007)
New Revision: 11055
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/various/Antenna.java
Log:
ANN-535
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-01-17 19:35:34 UTC (rev 11054)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-01-17 20:07:04 UTC (rev 11055)
@@ -1,20 +1,23 @@
//$Id$
package org.hibernate.cfg.annotations;
+import java.util.Iterator;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.AnnotationException;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.cfg.Ejb3Column;
import org.hibernate.cfg.ExtendedMappings;
import org.hibernate.cfg.PropertyHolder;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value;
-import org.hibernate.mapping.PropertyGeneration;
+import org.hibernate.mapping.Column;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
-import org.hibernate.AnnotationException;
import org.hibernate.util.StringHelper;
/**
@@ -101,7 +104,9 @@
if ( log.isDebugEnabled() ) {
log.debug( "binding property " + name + " with lazy=" + lazy );
}
- String containerClassName = holder == null ? null : holder.getClassName();
+ String containerClassName = holder == null ?
+ null :
+ holder.getClassName();
SimpleValueBinder value = new SimpleValueBinder();
value.setMappings( mappings );
value.setPropertyName( name );
@@ -124,35 +129,31 @@
prop.setName( name );
prop.setNodeName( name );
prop.setValue( value );
- prop.setInsertable( insertable );
- prop.setUpdateable( updatable );
prop.setLazy( lazy );
prop.setCascade( cascade );
prop.setPropertyAccessorName( propertyAccessorName );
- Generated ann = property != null ?
+ Generated ann = property != null ?
property.getAnnotation( Generated.class ) :
null;
GenerationTime generated = ann != null ?
ann.value() :
null;
- if (generated != null) {
- if ( ! GenerationTime.NEVER.equals( generated ) ) {
+ if ( generated != null ) {
+ if ( !GenerationTime.NEVER.equals( generated ) ) {
if ( property.isAnnotationPresent( javax.persistence.Version.class )
&& GenerationTime.INSERT.equals( generated ) ) {
- throw new AnnotationException("@Generated(INSERT) on a @Version property not allowed, use ALWAYS: "
+ throw new AnnotationException( "@Generated(INSERT) on a @Version property not allowed, use ALWAYS: "
+ StringHelper.qualify( holder.getPath(), name ) );
}
- if ( prop.isInsertable() ) {
- throw new AnnotationException("Cannot have @Generated property and insertable columns: "
- + StringHelper.qualify( holder.getPath(), name ) );
+ insertable = false;
+ if ( GenerationTime.ALWAYS.equals( generated ) ) {
+ updatable = false;
}
- if ( GenerationTime.ALWAYS.equals( generated ) && prop.isUpdateable() ) {
- throw new AnnotationException("Cannot have @Generated(ALWAYS) property and updatable columns: "
- + StringHelper.qualify( holder.getPath(), name ) );
- }
prop.setGeneration( PropertyGeneration.parse( generated.toString().toLowerCase() ) );
}
}
+ prop.setInsertable( insertable );
+ prop.setUpdateable( updatable );
log.trace( "Cascading " + name + " with " + cascade );
return prop;
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/various/Antenna.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/various/Antenna.java 2007-01-17 19:35:34 UTC (rev 11054)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/various/Antenna.java 2007-01-17 20:07:04 UTC (rev 11055)
@@ -14,7 +14,7 @@
@Entity
public class Antenna {
@Id public Integer id;
- @Generated(GenerationTime.ALWAYS) @Column(insertable = false, updatable = false)
+ @Generated(GenerationTime.ALWAYS) @Column()
public String longitude;
@Generated(GenerationTime.INSERT) @Column(insertable = false)
17 years, 7 months
Hibernate SVN: r11054 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/validator/test and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-17 14:35:34 -0500 (Wed, 17 Jan 2007)
New Revision: 11054
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Address.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Form.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Member.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/ValidTest.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
Log:
ANN-511 reflectionManager forgotten
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-17 01:11:37 UTC (rev 11053)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-17 19:35:34 UTC (rev 11054)
@@ -139,6 +139,7 @@
XClass beanXClass, ResourceBundle resourceBundle, MessageInterpolator userInterpolator,
Map<XClass, ClassValidator> childClassValidators, ReflectionManager reflectionManager
) {
+ this.reflectionManager = reflectionManager;
this.beanClass = reflectionManager.toClass( beanXClass );
this.messageBundle = resourceBundle == null ?
getDefaultResourceBundle() :
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Address.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Address.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Address.java 2007-01-17 19:35:34 UTC (rev 11054)
@@ -0,0 +1,17 @@
+//$Id: $
+package org.hibernate.validator.test.valid;
+
+import org.hibernate.validator.NotNull;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Address {
+
+ private String city;
+
+ @NotNull
+ public String getCity() {
+ return city;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Form.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Form.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Form.java 2007-01-17 19:35:34 UTC (rev 11054)
@@ -0,0 +1,21 @@
+//$Id: $
+package org.hibernate.validator.test.valid;
+
+import org.hibernate.validator.Valid;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Form {
+
+ private Member member;
+
+ @Valid
+ public Member getMember() {
+ return member;
+ }
+
+ public void setMember(Member m) {
+ this.member = m;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Member.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Member.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/Member.java 2007-01-17 19:35:34 UTC (rev 11054)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.validator.test.valid;
+
+import org.hibernate.validator.Valid;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Member {
+
+ private Address address;
+
+ @Valid
+ public Address getAddress() {
+ return address;
+ }
+
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/ValidTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/ValidTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/valid/ValidTest.java 2007-01-17 19:35:34 UTC (rev 11054)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.validator.test.valid;
+
+import junit.framework.TestCase;
+import org.hibernate.validator.ClassValidator;
+import org.hibernate.validator.InvalidValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ValidTest extends TestCase {
+ public void testDeepValid() throws Exception {
+ ClassValidator<Form> formValidator = new ClassValidator<Form>(Form.class);
+ Address a = new Address();
+ Member m = new Member();
+ m.setAddress( a );
+ Form f = new Form();
+ f.setMember(m);
+ InvalidValue[] values = formValidator.getInvalidValues( f );
+ assertEquals( 1, values.length );
+ }
+}
17 years, 7 months
Hibernate SVN: r11053 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/test/annotations/manytoone and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-16 20:11:37 -0500 (Tue, 16 Jan 2007)
New Revision: 11053
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java
Log:
ANN-515 use quoted name when copying join columns
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2007-01-17 00:40:54 UTC (rev 11052)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2007-01-17 01:11:37 UTC (rev 11053)
@@ -314,7 +314,8 @@
*/
public void linkValueUsingAColumnCopy(Column column, SimpleValue value) {
initMappingColumn(
- column.getName(),
+ //column.getName(),
+ column.getQuotedName(),
null, column.getLength(),
column.getPrecision(),
column.getScale(),
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java 2007-01-17 00:40:54 UTC (rev 11052)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java 2007-01-17 01:11:37 UTC (rev 11053)
@@ -21,7 +21,7 @@
@Formula("(1/focal)")
private float length;
@ManyToOne()
- @JoinColumn(name="frame_fk", referencedColumnName = "name")
+ @JoinColumn(name="`frame_fk`", referencedColumnName = "name")
private Frame frame;
public Long getId() {
17 years, 7 months
Hibernate SVN: r11052 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/test/annotations/onetomany and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-16 19:40:54 -0500 (Tue, 16 Jan 2007)
New Revision: 11052
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
Log:
ANN-516 support for @OrderBy and @Inheritance(JOINED)
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-16 23:24:17 UTC (rev 11051)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-17 00:40:54 UTC (rev 11052)
@@ -836,11 +836,19 @@
+ associatedClass.getEntityName() + "." + property
);
}
-
+ PersistentClass pc = p.getPersistentClass();
+ String table;
+ if (pc != associatedClass) {
+ table = pc.getTable().getQuotedName() + ".";
+ }
+ else {
+ table = "";
+ }
Iterator propertyColumns = p.getColumnIterator();
while ( propertyColumns.hasNext() ) {
Selectable column = (Selectable) propertyColumns.next();
- orderByBuffer.append( column.getText() )
+ orderByBuffer.append( table )
+ .append( column.getText() )
.append( " " )
.append( ordering.get( index ) )
.append( ", " );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-01-16 23:24:17 UTC (rev 11051)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-01-17 00:40:54 UTC (rev 11052)
@@ -7,6 +7,7 @@
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.Set;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
@@ -377,6 +378,27 @@
s.close();
}
+ public void testOrderByOnSuperclassProperty() {
+ OrganisationUser user = new OrganisationUser();
+ user.setFirstName( "Emmanuel" );
+ user.setLastName( "Bernard" );
+ user.setIdPerson( new Long(1) );
+ user.setSomeText( "SomeText" );
+ Organisation org = new Organisation();
+ org.setIdOrganisation( new Long(1) );
+ org.setName( "S Diego Zoo" );
+ user.setOrganisation( org );
+ Session s = openSession();
+ s.getTransaction().begin();
+ s.persist( user );
+ s.persist( org );
+ s.flush();
+ s.clear();
+ List l = s.createQuery( "select org from Organisation org left join fetch org.organisationUsers" ).list();
+ s.getTransaction().rollback();
+ s.close();
+ }
+
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
@@ -396,7 +418,10 @@
City.class,
Street.class,
PoliticalParty.class,
- Politician.class
+ Politician.class,
+ Person.class,
+ Organisation.class,
+ OrganisationUser.class
};
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java 2007-01-16 23:24:17 UTC (rev 11051)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java 2007-01-17 00:40:54 UTC (rev 11052)
@@ -0,0 +1,60 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table( name = "ORGANISATION" )
+public class Organisation implements Serializable {
+
+ private Long idOrganisation;
+ private String name;
+ private Set<OrganisationUser> organisationUsers;
+
+ public Organisation() {
+ }
+
+ public void setIdOrganisation(Long idOrganisation) {
+ this.idOrganisation = idOrganisation;
+ }
+
+ @Id
+ @Column( name = "id_organisation", nullable = false )
+ public Long getIdOrganisation() {
+ return idOrganisation;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Column( name = "name", nullable = false, length = 40 )
+ public String getName() {
+ return name;
+ }
+
+ public void setOrganisationUsers(Set<OrganisationUser> organisationUsers) {
+ this.organisationUsers = organisationUsers;
+ }
+
+ @OneToMany( mappedBy = "organisation",
+ fetch = FetchType.LAZY,
+ cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
+ @OrderBy( value = "firstName" )
+ public Set<OrganisationUser> getOrganisationUsers() {
+ return organisationUsers;
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java 2007-01-16 23:24:17 UTC (rev 11051)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java 2007-01-17 00:40:54 UTC (rev 11052)
@@ -0,0 +1,46 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@PrimaryKeyJoinColumn( name = "id_organisation_user" )
+@Table( name = "ORGANISATION_USER" )
+public class OrganisationUser extends Person implements Serializable {
+
+ private String someText;
+ private Organisation organisation;
+
+ public OrganisationUser() {
+ }
+
+ public void setSomeText(String someText) {
+ this.someText = someText;
+ }
+
+ @Column( name = "some_text", nullable=true,length=1024)
+ public String getSomeText() {
+ return someText;
+ }
+
+ public void setOrganisation(Organisation organisation) {
+ this.organisation = organisation;
+ }
+
+ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
+ @JoinColumn( name = "fk_id_organisation", nullable = false )
+ public Organisation getOrganisation() {
+ return organisation;
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java 2007-01-16 23:24:17 UTC (rev 11051)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java 2007-01-17 00:40:54 UTC (rev 11052)
@@ -0,0 +1,55 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.InheritanceType;
+import javax.persistence.Inheritance;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Inheritance( strategy = InheritanceType.JOINED )
+@Table( name = "PERSON_Orderby" )
+public class Person implements Serializable {
+
+ private Long idPerson;
+ private String firstName, lastName;
+
+ public Person() {
+ }
+
+ public void setIdPerson(Long idPerson) {
+ this.idPerson = idPerson;
+ }
+
+ @Id
+ @Column( name = "id_person", nullable = false )
+ public Long getIdPerson() {
+ return idPerson;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Column( name = "first_name", length = 40, nullable = false )
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Column( name = "last_name", length = 40, nullable = false )
+ public String getLastName() {
+ return lastName;
+ }
+
+}
+
17 years, 7 months
Hibernate SVN: r11051 - trunk/Hibernate3/src/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-16 18:24:17 -0500 (Tue, 16 Jan 2007)
New Revision: 11051
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/Mappings.java
Log:
synchronize branch_3_2 and head
Modified: trunk/Hibernate3/src/org/hibernate/cfg/Mappings.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/Mappings.java 2007-01-16 23:22:50 UTC (rev 11050)
+++ trunk/Hibernate3/src/org/hibernate/cfg/Mappings.java 2007-01-16 23:24:17 UTC (rev 11051)
@@ -490,7 +490,8 @@
}
while (finalName == null && currentTable != null);
if (finalName == null) {
- throw new MappingException( "Unable to find column with logical name: " + table.getName() + "." + logicalName);
+ throw new MappingException( "Unable to find column with logical name "
+ + logicalName + " in table " + table.getName() );
}
return finalName;
}
@@ -510,8 +511,8 @@
}
while (logical == null && currentTable != null && description != null);
if (logical == null) {
- throw new MappingException( "Unable to find logical column name from physical name: "
- + table.getName() + "." + physicalName );
+ throw new MappingException( "Unable to find logical column name from physical name "
+ + physicalName + " in table " + table.getName() );
}
return logical;
}
17 years, 7 months