Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JBoss, PostgreSQL, XDoclet, Serial primary keys in CMP

Reply
Thread Tools

JBoss, PostgreSQL, XDoclet, Serial primary keys in CMP

 
 
Richard Corfield
Guest
Posts: n/a
 
      04-21-2004
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

--
_/_/_/ _/_/_/ _/_/_/ Richard dot Corfield at ntlworld dot com
_/ _/ _/ _/
_/_/ _/ _/ Time is a one way street,
_/ _/ _/_/ _/_/_/ Except in the Twilight Zone.
 
Reply With Quote
 
 
 
 
Richard Corfield
Guest
Posts: n/a
 
      04-22-2004
Getting further, I've found the standardjbosscmp-jdbc.xml file in the
conf directory. This gives database mappings and <entity-command>s for
key generation. My task tonight perhaps, to either configure this for
postgresql (best), or use XDoclet's merge feature to add appropriate
entries to my jbosscmp-jdbc.xml. I notice that it supports JDBC3, so I
should be able to use that feature of the new Postgres driver.

- Richard

--
_/_/_/ _/_/_/ _/_/_/ Richard dot Corfield at ntlworld dot com
_/ _/ _/ _/
_/_/ _/ _/ Time is a one way street,
_/ _/ _/_/ _/_/_/ Except in the Twilight Zone.
 
Reply With Quote
 
 
 
 
Richard Corfield
Guest
Posts: n/a
 
      04-22-2004
On 2004-04-22, Richard Corfield <(E-Mail Removed)> wrote:
> Getting further, I've found the standardjbosscmp-jdbc.xml file in the
> conf directory. This gives database mappings and <entity-command>s for
> key generation. My task tonight perhaps, to either configure this for
> postgresql (best), or use XDoclet's merge feature to add appropriate
> entries to my jbosscmp-jdbc.xml. I notice that it supports JDBC3, so I
> should be able to use that feature of the new Postgres driver.


Getting even further. It's creating the rows, and they're being comitted
(must look at that transaction isolation) but is failing to serialise
the value object back to my test client as its primary key field of
type Object is not serializable of course. A task for later, but now
off to work.

The Value Object comes from XDoclet, and I'd like to stick to using that,
but I've hand hacked the jbosscmp-jdbc.xml to contain

<unknown-pk>
<unknown-pk-class>java.lang.Long</unknown-pk-class>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>SERIAL</sql-type>
<auto-increment/>
</unknown-pk>

and JBoss' standardjbosscmp-jdbc.xml has

<defaults>
<datasource>java:/DefaultDS</datasource>
<datasource-mapping>PostgreSQL 7.2</datasource-mapping>

... as before ...

<unknown-pk>
<unknown-pk-class>java.lang.Long</unknown-pk-class>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>SERIAL</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="postgresql-fetch-seq"/>
<!-- Tried JDBC3, but it didn't work! Postgres reports
not implemented yet. -->

</defaults>

If I can have it use that unknown-pk from defaults, then I can hopefuly
use an XDoclet generated unknown-pk without resorting to patching or
merge files. It would also make sense to put this info in defaults, so
if I change database later, I don't need to change all my packaged
beans.

- Richard

--
_/_/_/ _/_/_/ _/_/_/ Richard dot Corfield at ntlworld dot com
_/ _/ _/ _/
_/_/ _/ _/ Time is a one way street,
_/ _/ _/_/ _/_/_/ Except in the Twilight Zone.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to link foreign keys & primary keys using python? Harry George Python 9 06-13-2006 06:29 AM
Multiple primary keys with a datagrid? =?Utf-8?B?RGF2ZQ==?= ASP .Net 7 12-15-2004 05:49 PM
serial keys/validation keys sandeep Kanwal C++ 1 10-29-2004 06:36 PM
no cmp field defined in cmp ejb Andrea Sansottera Java 0 07-16-2004 02:24 PM
CMR/CMP and Compound Primary Key Damir Mikoc Java 1 07-04-2003 03:27 AM



Advertisments