Hello!

I'm using XDoclet2 for about a month and think that it is a great part of 
software, and a nice job you have done. 

BUT - I had a problem today. I'm using XDoclet2 to generate Hibernate-Mapping 
files. In a special case this does not work properly. 

First, I'm using Java 1.5 Typesafe Enums. Correct syntax with enums seem to 
crash the XDoclet parser:

public enum TestEnum {
  Value1, Value2;  
}
E:\build.xml:28: com.thoughtworks.qdox.parser.ParseException: syntax error 
@[x,y] in file:/E:/DerivedClass.java

The parser does not like the semi-colon after "Value2", which is correct syntax 
according to the "Planet" example in 
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html and the javac 
likes it as well. But that is not the big problem. Just to let u know. I just 
remove the semi-colon for now (which is correct syntax as well).

The main problem is that if I use the @hibernate.typdef tag in a 
@hibernate.joined-subclass tag it does not lead to any XML output in the 
generated mapping file. Example:

==== BaseClass.java ====
package at.arcsmed.kio.beans;

/**
 * @hibernate.class
 *   table = "Base_Class"
 */
public class BaseClass {
    /**
     * @hibernate.id
     *   generator-class = "native"
     */
    private int id;

    /**
     * @return Returns the id.
     */
    public int getId() {
        return id;
    }

    /**
     * @param id The id to set.
     */
    public void setId(int id) {
        this.id = id;
    }   
}
==== DerivedClass.java ====
package at.arcsmed.kio.beans;
// i've used the GenericEnumUserType from http://hibernate.org/272.html
/**
 * @hibernate.joined-subclass
 *   table = "DerivedClass"
 *   
* @hibernate.typedef
 *   name = "TestEnumType"
 *   class = "at.arcsmed.kio.beans.enums.GenericEnumUserType"
 * @hibernate.typedef-param
 *   typedef-name = "TestEnumType"
 *   name = "enumClass" 
 *   value = "at.arcsmed.kio.beans.DerivedClass$TestEnum" 
 */
public class DerivedClass extends BaseClass {
    public enum TestEnum {
        Value1, Value2
    }

    /**
     * @hibernate.property
     *   type = "TestEnumType"
     */
    private TestEnum test;

    /**
     * @return Returns the test.
     */
    public TestEnum getTest() {
        return test;
    }

    /**
     * @param test The test to set.
     */
    public void setTest(TestEnum test) {
        this.test = test;
    }
}
==== BaseClass.hbm.xml (generated via xdoclet2) ====
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd";>

<hibernate-mapping>
  <class table="Base_Class" name="at.arcsmed.kio.beans.BaseClass">
    <id name="id">
      <generator class="native"/>
    </id>
    <joined-subclass name="at.arcsmed.kio.beans.DerivedClass" 
table="DerivedClass">
      <key/>
      <property name="test" type="TestEnumType"/>
    </joined-subclass>
  </class>
</hibernate-mapping>

=============
There is no sign of my typedef :-(. While creating the example i realised, that 
there is a problem with the ANT integration as well. If i make changes to the 
DerivedClass.java-File, the BaseClass.hbm.xml file is not re-generated! This 
problem is probably a result of the fact, that the DerivedClass-Mapping must be 
included in the mapping file of BaseClass (a speciality of the Hibernate DTD). 
The solution is, to create the typedef-element in BaseClass.hbm.xml outside the 
class element (this must happen for the whole inheritance tree - so for 
joined-subclass elements in joined-subclass elements as well). So here is the 
proper BaseClass.hbm.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd";>

<hibernate-mapping>
  <typedef class="at.arcsmed.kio.beans.enums.GenericEnumUserType" 
name="TestEnumType">
    <param name="enumClass">at.arcsmed.kio.beans.DerivedClass$TestEnum</param>
  </typedef>
  <class table="Base_Class" name="at.arcsmed.kio.beans.BaseClass">
    <id name="id">
      <generator class="native"/>
    </id>
    <joined-subclass name="at.arcsmed.kio.beans.DerivedClass" 
table="DerivedClass">
      <key/>
      <property name="test" type="TestEnumType"/>
    </joined-subclass>
  </class>
</hibernate-mapping>

As a result of the missing typedef I get an error during the creation of the 
database schema with hibernate: 
Exception in thread "main" org.hibernate.MappingException: Could not determine 
type for: TestEnumType, for columns: [org.hibernate.mapping.Column(test)]
     [java] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:265)
     [java] at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:128)
     [java] at org.hibernate.mapping.Column.getSqlType(Column.java:172)
     [java] at org.hibernate.mapping.Table.sqlCreateString(Table.java:263)
     [java] at 
org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:669)
     [java] at 
org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:65)
     [java] at 
org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:49)
     [java] at 
at.arcsmed.kio.test.HibernateSchema.createSchema(HibernateSchema.java:29)
     [java] at at.arcsmed.kio.test.HibernateSchema.main(HibernateSchema.java:24)

I hope this issues can be addressed somehow,

regards
Christoph

===========================================

  DI Christoph ADL
  ARC Seibersdorf research GmbH
  Biomedical Engineering / eHealth systems

  Viktor-Kaplan-Straße 2/1
  A-2700 Wiener Neustadt, Austria

  T: +43 (0)2622 69290-41
  F: +43 (0)2622 69290-24
  E: [EMAIL PROTECTED]
  H: www.arcsmed.at

Reply via email to