R
Richard Corfield
I'm trying to get a simple container managed bean to work with JBoss
3.2, PostgreSQL and Container Managed Persistence. I thought it would be
a good learning excercise. I wonder what techniques other people on this
newsgroup prefer for data access.
I've been impressed with XDoclet so far, as it has made things quite easy,
if only things worked.
I've tried a few variations:
Using the bean level tag:
* @jboss.unknown-pk
* class="java.lang.Long"
* readonly="true"
* column-name="reminder_id"
* auto-increment="true"
with an ID field defined as
/**
* @ejb.pk-field
*
* @ejb.persistence
* column-name="reminder_id"
*
* <!-- This should be for granted as its a pk-field? -->
* @ejb.value-object
* match="light"
*/
public abstract Long getID();
public abstract void setID(Long lID);
and manually creating the table with a SERIAL column for reminder_id.
Unfortunately when I run ejbCreate, I get a Not-Null constraint
violation on reminder_id. Presumably JBoss is setting that column to
NULL on the INSERT clause.
Another one from something I read on the JBoss pages was to define a
primary key of type Object. This doesn't help me refer to things by
primary key, for example in an Edit command on a web page - edit.do?id=123.
* @ejb.pk
* class="java.lang.Object"
* generate="false"
* @jboss.unknown-pk
* class="java.lang.Object"
* column-name="reminder_id"
* auto-increment="true"
and no @ejb.pk-fields.
This time its trying to recreate the table, and failing because Postgres
doesn't have an IDENTITY type. Changing back to Hypersonic gets closer,
telling me that IDENTITY and VARCHAR(32) don't mix, a change of SQL
data type in the @ejb.pk tag perhaps, but I'm moving further away from
numeric keys and my choice of database.
CMP beans and XDoclet seem to be a quite easy way (if it worked, or
assuming you know what you're doing) of getting a data access layer.
I've also looked at Hibernate, but wonder about my Hibernate classes
containing what are really Hibernate implementations of List and Set
being returned to the presentation layer. Of course I can avoid using
relationships in Hibernate, and I have a quick way of getting where I
was with Data Access Object, but with added features such as versioning.
Using Hibernate as part of the Model in a Struts based web page looks
worth exploring though, though I'd have to explore how I look after the
Session object and manage commit and disposal. I've used Command Object
pattern to deal with JDBC transactions in my fat client work.
I've used custom Data Access Objects encapsulating JDBC calls in my last
two major Java projects, and wondered if there was something easier.
Thanks
- Richard
3.2, PostgreSQL and Container Managed Persistence. I thought it would be
a good learning excercise. I wonder what techniques other people on this
newsgroup prefer for data access.
I've been impressed with XDoclet so far, as it has made things quite easy,
if only things worked.
I've tried a few variations:
Using the bean level tag:
* @jboss.unknown-pk
* class="java.lang.Long"
* readonly="true"
* column-name="reminder_id"
* auto-increment="true"
with an ID field defined as
/**
* @ejb.pk-field
*
* @ejb.persistence
* column-name="reminder_id"
*
* <!-- This should be for granted as its a pk-field? -->
* @ejb.value-object
* match="light"
*/
public abstract Long getID();
public abstract void setID(Long lID);
and manually creating the table with a SERIAL column for reminder_id.
Unfortunately when I run ejbCreate, I get a Not-Null constraint
violation on reminder_id. Presumably JBoss is setting that column to
NULL on the INSERT clause.
Another one from something I read on the JBoss pages was to define a
primary key of type Object. This doesn't help me refer to things by
primary key, for example in an Edit command on a web page - edit.do?id=123.
* @ejb.pk
* class="java.lang.Object"
* generate="false"
* @jboss.unknown-pk
* class="java.lang.Object"
* column-name="reminder_id"
* auto-increment="true"
and no @ejb.pk-fields.
This time its trying to recreate the table, and failing because Postgres
doesn't have an IDENTITY type. Changing back to Hypersonic gets closer,
telling me that IDENTITY and VARCHAR(32) don't mix, a change of SQL
data type in the @ejb.pk tag perhaps, but I'm moving further away from
numeric keys and my choice of database.
CMP beans and XDoclet seem to be a quite easy way (if it worked, or
assuming you know what you're doing) of getting a data access layer.
I've also looked at Hibernate, but wonder about my Hibernate classes
containing what are really Hibernate implementations of List and Set
being returned to the presentation layer. Of course I can avoid using
relationships in Hibernate, and I have a quick way of getting where I
was with Data Access Object, but with added features such as versioning.
Using Hibernate as part of the Model in a Struts based web page looks
worth exploring though, though I'd have to explore how I look after the
Session object and manage commit and disposal. I've used Command Object
pattern to deal with JDBC transactions in my fat client work.
I've used custom Data Access Objects encapsulating JDBC calls in my last
two major Java projects, and wondered if there was something easier.
Thanks
- Richard