Author: max.andersen(a)jboss.com
Date: 2007-07-30 17:49:10 -0400 (Mon, 30 Jul 2007)
New Revision: 12851
Added:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DependentValue.hbm.xml
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/DefaultValueVisitor.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/EntityNameFromValueVisitor.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/JavaTypeFromValueVisitor.java
branches/Branch_3_2/HibernateExt/tools/src/templates/dot/entitygraph.dot.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
HBX-953 java.lang.UnsupportedOperationException: accept on
org.hibernate.mapping.DependantValue
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -369,4 +369,9 @@
public String getHibernateTypeName(Property p) {
return (String) p.getValue().accept(new EntityNameFromValueVisitor());
}
+
+
+ public String getSafeHibernateTypeName(Property p) {
+ return (String) p.getValue().accept(new EntityNameFromValueVisitor(false));
+ }
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -295,39 +295,7 @@
}
private String getJavaTypeName(Value value, boolean preferRawTypeNames) {
- if(true) return (String) value.accept( new JavaTypeFromValueVisitor() );
- if ( value instanceof Component) {
- // composite-element breaks without it.
- return ((Component)value).getComponentClassName();
- }
- if ( value instanceof ToOne ) {
- return ( (ToOne) value ).getReferencedEntityName(); // should get the cfg and lookup
the persistenclass.
- }
-
- if(value instanceof OneToMany) {
- return ((OneToMany)value).getAssociatedClass().getClassName();
- }
-
- try {
- // have to attempt calling gettype to decide if its custom type.
- Type type = value.getType();
- if(type instanceof CustomType || type instanceof CompositeCustomType) {
- return toName( type.getReturnedClass() );
- }
- } catch(HibernateException he) {
- // ignore
- }
-
- if ( preferRawTypeNames && value.isSimpleValue() ) {
- // this logic make us use the raw typename if it is something else than an Hibernate
type. So, if user wrote long we will use long...if he meant to have a Long then he should
use the java.lang.Long version.
- String typename = ( (SimpleValue) value ).getTypeName();
- if ( !isNonPrimitiveTypeName( typename ) ) {
- String val = ( (SimpleValue) value ).getTypeName();
- if(val!=null) return val; // val can be null when type is any
- }
- }
-
- return toName( value.getType().getReturnedClass() );
+ return (String) value.accept( new JavaTypeFromValueVisitor() );
}
public String asParameterList(Iterator fields, boolean useGenerics, ImportContext ic) {
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/DefaultValueVisitor.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/DefaultValueVisitor.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/DefaultValueVisitor.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -14,6 +14,7 @@
import org.hibernate.mapping.PrimitiveArray;
import org.hibernate.mapping.Set;
import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.Value;
import org.hibernate.mapping.ValueVisitor;
/**
@@ -35,8 +36,9 @@
this.throwException = throwException;
}
- protected Object handle(Object o) {
+ protected Object handle(Value o) {
if (throwException) {
+
throw new UnsupportedOperationException("accept on " + o);
}
else { return null; }
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/EntityNameFromValueVisitor.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/EntityNameFromValueVisitor.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/EntityNameFromValueVisitor.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -21,6 +21,10 @@
super( true );
}
+ public EntityNameFromValueVisitor(boolean b) {
+ super(b);
+ }
+
public Object accept(OneToOne o) {
return acceptToOne(o);
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/JavaTypeFromValueVisitor.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/JavaTypeFromValueVisitor.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/visitor/JavaTypeFromValueVisitor.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -55,7 +55,7 @@
}
}
- protected Object handle(Object o) {
+ protected Object handle(Value o) {
Value value = (Value) o;
try {
// have to attempt calling gettype to decide if its custom type.
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/dot/entitygraph.dot.ftl
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/templates/dot/entitygraph.dot.ftl 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/templates/dot/entitygraph.dot.ftl 2007-07-30
21:49:10 UTC (rev 12851)
@@ -59,7 +59,7 @@
<#macro propertyEdges root properties>
/* Property edges/nodes for ${root} */
<#foreach property in properties>
- <#if c2h.getHibernateTypeName(property)?exists>
+ <#if c2h.getSafeHibernateTypeName(property)?exists>
${root} ->
${c2h.getHibernateTypeName(property)?replace(".","_dot_")} [
label="${property.name}"
<#if c2j.isComponent(property)>
Added:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DependentValue.hbm.xml
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DependentValue.hbm.xml
(rev 0)
+++
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DependentValue.hbm.xml 2007-07-30
21:49:10 UTC (rev 12851)
@@ -0,0 +1,28 @@
+<?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>
+
+<!-- Mapping for dependentValue bug - HBX-953 -->
+ <class name="Foo" table="foo">
+ <id name="id" type="java.lang.Integer"
unsaved-value="null" >
+ <column name="foo_id" sql-type="int"
not-null="true" />
+ <generator class="native"/>
+ </id>
+ <list name="bars"
+ table="bar"
+ lazy="false"
+ cascade="all">
+ <key column="foo_id" not-null="true"/>
+ <list-index column="ordering" />
+ <one-to-many class="Bar" />
+ </list>
+ </class>
+ <class name="Bar" table="bar">
+ <id name="id" type="java.lang.Integer"
unsaved-value="null" >
+ <column name="bar_id" sql-type="int"
not-null="true" />
+ <generator class="native"/>
+ </id>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2007-07-30
19:29:48 UTC (rev 12850)
+++
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2007-07-30
21:49:10 UTC (rev 12851)
@@ -23,7 +23,8 @@
"LineItem.hbm.xml",
"Product.hbm.xml",
"HelloWorld.hbm.xml",
- "UnionSubclass.hbm.xml"
+ "UnionSubclass.hbm.xml",
+ "DependentValue.hbm.xml"
};
}
Show replies by date