-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: XDoclet 1.2.2+Hibernate 2.1.8+SQLServer2K: A few problems
PostPosted: Mon Mar 28, 2005 10:03 am 
Newbie

Joined: Mon Mar 28, 2005 9:20 am
Posts: 1
Hi,

I'm moving to Hibernate from OJB, and encountered a few problems when going on the path java->hbm->ddl sql, I have done some search on both XDoclet's website and Hibernate resources, without much success. I wonder if experienced users here can give me some pointers.

1. SchemaExport sql generation problem against SQLServer 2000:
Generated hibernate.cfg.xml (partial)
Code:
   <session-factory>

      <!-- properties -->
      <property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
      <property name="show_sql">false</property>
      <property name="use_outer_join">false</property>
         <property name="connection.username">sa</property>
         <property name="connection.password">sa</property>
         <property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
         <property name="connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb;SelectMethod=cursor</property>

      <!-- mapping files -->
      <mapping resource="..."/>
   </session-factory>

My SchemaExport Ant task:
Code:
   <target name="generate.sql"
      description="Generate SQL script">
      <taskdef name="schemaexport"
         classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
         classpathref="classpath.runtime"/>
      <schemaexport
         config="${dir.conf}/hibernate.cfg.xml"
         quiet="no"
         text="yes"
         drop="no"
         delimiter=";"
         output="${dir.sql}/db_schema.sql"/>
   </target>

The problems are: a) When text is set to "no", the database tables are not created. There're no errors. b) When text is set to "yes", the sql file is generated successfully, but with simple "drop xxx; create xxx..." pair. This does not work well since the first time it is used against an empty database, SQLServer will signal error for "drop xxx" since xxx doesn't exist at that time. I used the sql task with onerror="continue" to get around this problem, but it's not pretty.

2. XDoclet @hibernate.component produce wrong class name for inner class:
I have a Type class inside the User class, which is used as a component property of the User class:
Code:
package eg;
public class User {
    public static final class Type {...}
    private Type type;
    ....
}

If I mark getType() with @hibernate.component, without any attributes, the class attribute will be generated by XDoclet as "eg.User.Type", which is wrong since Hibernate requires "eg.User$Type". Now I have to specify class attribute explicitly to get around this.

3. Is there a way to add the package attribute to hibernate-mapping in the generated hbm.xml? I don't think merge file will do the trick.

4. Database Index & Unique:
a) Is there a way to specify the exact name of the generated index or unique constraint? If I add unqiue="true" to a column, SQLServer will generate a random suffix for my unique constraint name, which is ugly.
b) I have trouble generating database index, here's an property of my domain class:
Code:
    /**
     * @return Returns the name.
     * @hibernate.property column = "NAME" length = "20" not-null="true" index="IDX_NAME"
     */
    public String getName()
    {
        return name;
    }

If I run hibernatedoclet against it
Code:
   <target name="generate.hibernate"
      description="Generates Hibernate class descriptor files.">
      <taskdef name="hibernatedoclet"
          classname="xdoclet.modules.hibernate.HibernateDocletTask">
         <classpath refid="classpath.build"/>
      </taskdef>      
      <hibernatedoclet
          destDir="${dir.conf}"
          excludedTags="@version,@author,@todo"
          force="true"
          mergeDir="${dir.conf}/hibernate"
          verbose="false">

          <fileset dir="${dir.src.java}">
              <include name="eg/*.java"/>
          </fileset>

          <hibernate validatexml="true" version="2.0"/>
         <hibernatecfg
            driver="${db.jdbc.driver}"
            jdbcUrl="${db.jdbc.url}"
            userName="${db.jdbc.userName}"
            password="${db.jdbc.password}"
            dialect="${db.dialect}"/>
      </hibernatedoclet>      
   </target>

The index is not generated in the hbm.xml:
Code:
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="NAME"
            length="20"
            not-null="true"
        />


Thanks for your help


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.