Tuesday, September 07, 2004

work stuff... naming conventions... the stuffs related to persistence was previously named like this:

e.g.
com.thecompany.hb.customers

contains both the interface and the implementation classes... hbm xdoclet generated files follows the same format except that its prefix is hbm, like hbm.thecompany.hb.customers

much to my front end pal's dismay i changed all the package names to follow this convention:

e.g.
com.thecompany.customers

to contain just the pojo and the dao and service interfaces... and for the actual implementation:

e.g.
com.thecompany.customers.hb

at least my co-developers will only need to worry about the interfaces and let me worry with the implementation... which is newly migrated to hibernate for now... but will likely try a jdo implementation in the near future...

spring framework is really doing a great job of supporting structures like this... and i can try varied implementations without driving my co-developers insane... also our discussions would be centered on services and dao's in a much more abstract way... shielding them away from the implementation and likewise do things in parallel based on assumptions... this also allows me to junit test the implementation as much as i want... the previous ejb cmp/cmr implementation was such a pain to test...

on hibernate... using the postgres sequence with it was not clearly documented... or it took me a good deal of google time to find out...

for example you have a sequence and a table like this:

create sequence customer_id_seq;

and you have a table like so:

create table customers (
id integer DEFAULT nextval('customer_id_seq') NOT NULL,
name varchar(20),
address varchar(5),
constraint custumers_pk primary key (id)
);

the correct xdocletized pojo class would be:

/**
* @hibernate.class table="customers"
*
**/
public class Customer {
// primary key field
private java.lang.Long id;

// other fields
private java.lang.String name;
private java.lang.String address;

// eclipse's generate getters and setters...

// here is the correct xdoclet tag to be able to use the
// postgres sequence
/**
* @return Returns the id.
*
* @hibernate.id generator-class="sequence"
*
* @hibernate.generator-param name="sequence" value="customer_id_seq"
**/
public java.lang.Long getId() {
return id;
}

// other getters and setters here....
...
}

there... hope this could be of help to anyone who wants to get his sequences to work with hibernate and is using xdoclet to generate the mapping files...


change topic... firefox crashes evertime i visit a flash enabled site... reinstalling and upgrading doesnt help... cant pinpoint if the problem is gentoo, xorg or linux specific...

No comments: