Discussion:
[Hibernate] Xdoclet stuffs...
Mauro Sergio Silva
2003-12-14 00:32:00 UTC
Permalink
Hi guys.

I'm developing an application using Hibernate 2.1 with MySql and have some
coments about
continuos integration with you. When I tryied to configure my project using
ant xdoclet to export my schema I've noted that it seams that hibernate
doclets doesn't suport the column element inside propertys, so I culd not
custumize my ddl's. After read some chapters of Xdoclet in Action it seams
to be easy do waht I nedd to do so I decide to take a look in hibenate
modules to see how culd i custumize my templates to support the columns tag.
I've got I good surprise to see that there was an hibernate-column.xdt(xdt
is the doclet tamplate file extension) that was patched by Gaving King (I
think..) that was marged in propertys tamplets so I culd use a doclte like
that:

...
@hibernate.property
@hibernate.column name="foo" sql-type="text"
public String getFoo(){
...

to generate this maping (using MySql dialect)

...
<property
name="foo"
type="java.lang.String"
update="true"
insert="true"
<column
name="foo"
sql-type="text"
/>
</property>
...

Greats now I culd use xdoclet to generate my custumized maping and generate
custumized ddl and I ned to do nothing!.
The next step was that I've decide to use uuid.hex as my id generator, and
i've noticed at first that the hibenate.column was marged
only in hibenate.propertys and I changed the hibernate.xdt and
hibernate-column.xdt to marge columns in id tags and generate the columns
atribute
for both the id and property elemenst .I've submited a patch to xdoclet
project ( I dont now how bug free it is, but until now it works nice to me).
As I was using the rc1 of hibernate I've noticed that that schema export
doesnt care about the column elements in id elements and I've decide to
use the final release to make a unit test and patch the code to generate the
type of column used by primary key in the generated script. good surprise
again
the final release was bug free (do nothing again) and generates my id rights
again and I culd use tags like this.
....
@hibenate.id generator-class = "uuid.hext"
@hibernate.column name = "oid" sql-type = "varchar(32)"
public String getOid () {
...
to generate this map ...

<id
name="id"
<column
name="oid"
sql-type="varchar(32)"
/>
<generator class="uuid.hex">
</generator>
</id>


and this script

...
[schemaexport] oid varchar(32) not null,
...
[schemaexport] primary key (oid)

...

Using string.hex was my decision couse its much flexible and I'm thinking
use clusterb (C-JDBC) to cluster my database in future...

...


I hope that it culd be usefull to someone else

Mauro
Mauro Sergio Silva
2003-12-16 10:20:01 UTC
Permalink
----- Original Message -----
From: "Konstantin Priblouda" <***@yahoo.com>
To: "Mauro Sergio Silva" <***@automaware.com.br>
Sent: Tuesday, December 16, 2003 9:07 AM
Subject: Re: [Hibernate] Xdoclet stuffs...
Hi Konstantin
Hi Mario,
I think we shall move this tread to hibernate forum.
As you may see, we discussing this off the list, and
hibernate folks can not correct us.
( I'm already discussing xdoclet stuff there )
----- Original Message -----
Sent: Monday, December 15, 2003 11:55 AM
Subject: Re: [Hibernate] Xdoclet stuffs...
Sorry, I was thinking that it was an answer from
Hibernate-devel list(couse
the text appended in your e-mail)
Yes it was. But I happen to be xdoclet comiter,
and
I'm working on xdoclet2 plugin right now...
I think the confusion is couse the coment in
hibernate dtd.
It's in deed somehow confusing...
The column element that could be placed in
propertys
and ids is the only
place where I could use the sql-type attribute.
Hibernate has a tool called schemaexport that
reads
the hbm.xmls and
generate the schema of your database using those
informations, there is
other tool called schema update that generate
the
update of your schema
based in jdbc metada. If you want to custumize
the
ddl generated based in
your mapping files you culd put some
informations in
your
schema like sql-type to custumize the generated
ddl.
For example if you declare your id as an string
the
schemaexport will
generate your id as a varchar[255] for mysql
dialect. But if you use the
column element inside the id element and specify
the
sql-type attribute as
char[32], for example) the schema exprot will
generate your id column as a
varchar[32] for mysql dialect that is the right
column lenght to uuid.hex
( 32 lenght id).
I do not know much about schemaexport. But column
elements are somehow tricky, and not well
supported by
xdoclet. For nested column elements we will have
to
specify additional xdoclet tags ( for example like
@hibernate.key-column or @hibernate.index-column
)
And as those column sepcifications are required
only
for composite keys, alternative would be to look
up
class in question, and proces his ID properties...
( this is even more tricky, and this class is may
be
not available as source... )
This is exactly the point where we desagree. You
sad that column
specification is required only for composite keys,
but
there is other two situations where column element
is used in mapping files,
in both situations the column is used
to the same porpuse to custumize the ddl. I will use
some examples in the
ReferenceDocumentation 2.1 of Hibernate
to ilustrate what I'm talking about (the PDF version
to be much precise). I
know that you are not a Hibernate developer I'm
using the reference just to clarify my example.
First in page 4 Section 1.3 Mapping the cat in the
id element you culd see a
nested element column, custumizing the way
the ddl will be genertated. You culd see in this
example that the column
element culd be used in the id element, not in
composite key.
In the page 5 you culd see the same use of column
element inside the
property for the same porpouse.
In chapter 5 section 5.4 it talks about Custumizing
the DDL and it talks
about the use of column element iside a property.
You can see that
in the secon example it doesn't refeare about
sql-type attribute, couse if
you see in the dtd there is only one place where the
sql-type
attribute culd be used that is in the column
element.
On chapter 18 section 18.1.1 custumizing the schema
page 116 again you culd
see some examples using the column element.
In the version 1.2 b4 you culd use columns elemnts
in propertys to generate
mapping files like in the examples above becouse
the properties.xsd the column is merged inside
property and it generate the
column attribute or the column element if you use
the
the hibenate.property and hibernate.column in the
same method,it works fine.
What i did was patch the column.xsd and merged
it in the id element changind the hibernate.xsd too.
The point is if it is possible to use the colun
inside id ant property when
I write the mapping by hand Why it wuld not be
possible to generate
it using xdoclete, in fact with the 1.2b4 you culd
use it in propertys.
Well, our usage pattern does differ.
I never use schema export - I just dump my test
database ( produced by my unit tests ) and then
tune schema manually.
And it does not happen oft....
I see now, that I have to provide column elements
( and respective tags )
You may look into current development of xdoclet 2
plugin -- if you manage to compile verything
necessary...
( may be tricky )
Unfortunatly I culd not get the xdoclet version 2
from CVS. When I tryed to
do it in the sourceforge host there is a file saying
that the code was moved
to xdoclet.codehous.org but the code isnt there
too. :(.
This is also tricky :) There are several components
now
xdoclet itself lives at: xdoclet.codehaus.org
( you will need this, as well as generama - same
modules xdoclet / generama
)
- qdox ( qdox.codehaus.org ) -
- picocontainer
pico
- picoextras -
nano
they are at sourceforge as project xdoclet-plugins...
I can not promiss that everything will compile off the
shelf...
regards,
=====
----[ Konstantin Pribluda ( ko5tik ) ]----------------
Zu Verstärkung meines Teams suche ich ab Sofort einen
Softwareentwickler[In] für die Festanstellung.
Arbeitsort: Mainz
Skills: Programieren, Kentnisse in OpenSource-Bereich
----[ http://www.pribluda.de ]------------------------
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
Loading...