-->
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.  [ 12 posts ] 
Author Message
 Post subject: Schema Export for XDoclet2
PostPosted: Sun Mar 26, 2006 11:08 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
I start using XDoclet2 since it covers Java 5 features such as generics. Since I had a working project with XDoclet1, I modified it step-by-step to make it compatible with XDoclet2. Generating *.hbm.xml(s), was easily. However, I can not get through 'schemaexport' by getting the same error every time: "Schema text failed: Could not read mapping document from file:"

I'm using the same schemaexport I applied for *.hbm.xml(s) generated by XDoclet1. Do I have to provide schemaexport differently when I work with XDoclet2?

Code:
    <target name="schemaexport2" depends="hbmxdoclet2">
      <taskdef name="schemaexport"
            classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
            <classpath refid="classpath" />
      </taskdef>
      <schemaexport config="${basedir}/config/hibernate.cfg.xml"
                  quiet="no"
                  text="no"
                  drop="no"
                  delimiter=";"
         output="schema-export.sql">
        <fileset dir="${src}">
            <include name="**/*.hbm.xml"/>
        </fileset>
      </schemaexport>
    </target>

I appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 5:14 pm 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
This error has nothing to do with a wrong ant task. XDoclet2's hibernate plugin doesn't generate needed mapping file tags and options when they are not supplied. This results in invalid .hbm.xml files. Especially the type option for the property and id tags aren't generated with useful defaults when you don't supply them within your XDoclet2 comment. Funny enough these are optional parameters, nevertheless the SchemaExportTask seems to need those and others to run successfully. I'll tell you which comments I had to add in order to make this work when I'm back at work tomorrow morning.

Uli


Top
 Profile  
 
 Post subject: Schema Export for XDoclet2
PostPosted: Mon Mar 27, 2006 7:14 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Thank you for your reply. I noticed the difference between *.hbm.xml(s) generated by XDoclet1 and XDoclet2. According to the following results, it seems XDoclet2 does not generate useful defaults for type, update, and insert. This is not intuitive for the users moving from XDoclet1 to XDoclet2.

Java code :
Code:
/**
* @hibernate.property column="information" not-null="false"
*/
public String getInformation() { return information; }
public void setInformation(String info) { information = info; }

XDoclet1 result :
Code:
<property
  name="information"
  type="java.lang.String"
  update="true"
  insert="true"
  column="information"
  not-null="false"
/>

XDoclet2 result :
Code:
<property name="information" not-null="false" access="method" column="information"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 7:40 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
That's exactly what I meant. This is a flaw in XDoclet2's Hibernate plugin.
Unfortunately I deleted my test files so I can't give you more examples. I for one switched to Hibernate Annotations to describe the mappings directly in my Java source code. This works very well for me.

Uli


Top
 Profile  
 
 Post subject: Schema Export for XDoclet2
PostPosted: Mon Mar 27, 2006 8:12 pm 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
I found XDoclet2 always generates [ access="method" ] even though I explicitly specify access="property" in my Java source code. How did you get around this problem?

Java code :
Code:
/**
* @hibernate.property column="information" not-null="false" type="java.lang.String" update="true" insert="true" access="proxy"
*/
public String getInformation() { return information; }
public void setInformation(String info) { information = info; }


XDoclet2 result:
Code:
<property name="information" insert="true" not-null="false" type="java.lang.String" access="method" column="information" update="true"/>


The same story is ture for "lazy". XDoclet2 always generates [ lazy="false" ] even thogh I explicitly specify lazy="proxy". It seems XDoclet2 is not really matured yet.... With all this problems how do you manage Hibernate Annotations to describe the mappings directly in my Java source code? Please advise.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 1:37 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
You typed access="proxy" but I think access="property" should be correct. Is this just a copy/paste error? I'll send you some annotations examples when I'm at work.

Uli


Top
 Profile  
 
 Post subject: Schema Export for XDoclet2
PostPosted: Tue Mar 28, 2006 1:55 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Sorry... It was just a cut&past error. I used access="property" in my java code but XDoclet2 ignored it and changed it to access="method". Also XDoclet2 ignores lazy="proxy" and changes it to lazy="false". I really want to know how you got around this problem. I appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 4:43 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
Hi Keisuke,

I attached 3 Java Files and my hibernate configuration in this reply. The 2 classes Cat and DomesticCat should give you a starting point with Hibernate Annotations and the AnnoSchemaExport class shows you how to generate SQL for schema generation and export it to a database. As you will see, no mapping files are needed anymore which I think facilitates using Hibernate enormously. I strongly advise you to have a look at the Hibernate Annotations documentation which I think is very good.

Uli

Code:
@Entity
@Table(name="cat")
@Inheritance(strategy=InheritanceType.JOINED)
public class Cat {
   
    /* specifying the @Id annotation here corresponds to
     * access="field"
     */
   protected int id;
    /* specifying the @Basic annotation here corresponds to
     * access="field"
     */
   protected String sex;
   
   public Cat() {}
   
   public Cat(String sex) { this.sex = sex; }
   
   @Id
   @GeneratedValue(generator="autoinc")
   @GenericGenerator(name="autoinc", strategy="identity")
   public int getId() { return id; }
   public void setId(int id) { this.id = id; }
   
    /* omitting an annotation here is the same as providing
     * @Basic
     * The @Basic annotation allows to specify the FetchType,
     * e.q. @Basic(fetch=FetchType.LAZY)
     */
   public String getSex() { return sex; }
   public void setSex(String sex) { this.sex = sex; }
   
   public String toString() {
      return "I'm a " + sex + " Cat with ID " + id;
   }
}


Code:
@Entity
@Table(name="domesticcat")
public class DomesticCat extends Cat {
   
   String name;
   
   public DomesticCat() { super(); }
   
   public DomesticCat(String sex, String name) {
      super(sex);
      this.name = name;
   }
   
   public String getName() { return name; }
   public void setName(String name) { this.name = name; }
   
   public String toString() {
      return name + " is a " + sex + " DomesticCat with ID " + id;
   }
}


Code:
public class AnnoSchemaExport {
   public static void main(String[] args) {
      Configuration cfg = new AnnotationConfiguration().configure();
      SchemaExport se = new SchemaExport(cfg);
      se.create(true,true);
   }
}


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/xdb</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <mapping class="test.hb.Cat" />
        <mapping class="test.hb.DomesticCat" />
    </session-factory>
</hibernate-configuration>


P.S.: I left out the imports for brevity.


Top
 Profile  
 
 Post subject: Schema Export for XDoclet2
PostPosted: Wed Mar 29, 2006 6:47 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
This is a great example! For programmers nothing is more appealing than a real code. I net-surfed deeply but could not find an intuitive example like this. I'm sure this example will help a lot of other followers as well. I really appreciate your patience and kindness to have guided me through.


Top
 Profile  
 
 Post subject: OK but with Java 1.4 ?
PostPosted: Wed Mar 29, 2006 11:40 am 
Newbie

Joined: Wed Mar 29, 2006 11:33 am
Posts: 2
Hi all.
I have the same issue.
But unfortunatly, I cannot use Java 5 and must stay in a java 1.4 environment. Therefore I do not have access to the annotation feature and I must keep the XDoclet approach.

From what I have read in this topic, should I conclude XDoclet for Hibernate does not work ?

Thanks for your help.
Philippe.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 11:56 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
No, as the topic says, this is just a XDoclet2 issue. If you don't need support for generics (introduced in Java 5) you can just use XDoclet (1) which works very well. Besides, XDoclet2 IS working but without reasonable defaults which makes it uncomfortable.

Uli


Top
 Profile  
 
 Post subject: Swith to hibernate tool ant tasks
PostPosted: Wed Mar 29, 2006 12:17 pm 
Newbie

Joined: Wed Mar 29, 2006 11:33 am
Posts: 2
Finally I give up with schemaexport as I cannot find help anywhere and I cannot make it work simply (even with very basic mapping files written on my own).

But, I found help on Hibernate tools Ant tasks, and it works much better (and at least output messages are for errors are clear).

All necessary information is at http://forum.hibernate.org/viewtopic.php?t=951070

Hope this will help others.

Best regards
Philippe.


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

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.