I ended up writing a simple BMP entity bean that only provides a create() 
method through the home interface.  This bean is db platform independent, 
since (at least in my case) it only uses one SQL 92 compliant statement.  
However, it is not db-schema independent for obvious reasons.  my current 
requirements dictate that I have two versions of my entity dd's, one for the 
default JbossCMP-generated schema and one set of dd's mapped to existing 
schema.  so, i really only need to have two versions of my BMP entity, and 
since it basically only has one method (ejbCreate()) it works out pretty 
well.

however, I think that the ability to specify a primary key field as 
'datasource-provided' in the jbosscmp-jdbc dd would be a useful feature in 
JBoss.  Is this logically sound or am I missing something here?  JBoss would 
only have to check for the presence of this tag and, if present, not include 
this column in the generated SQL insert statement.

thoughts?
Justin

> I had this exact scenario with using auto-generated PK's in Postgres
> (serial datatype).  Being new to EJB/JBoss, my short term solution just
> to get something working was to actually use my datasource and query the
> sequence during the creation of the EJB.  This works fine, but obviously
> ties your bean to a specific datasource & database.
>
> My next plan is to maybe use a stateless session bean and have some sort
> of resource manager facility that the beans could use to request PK
> id's.  The resource manager could do the work of actually using the
> underlying sequences and feed the information back.  With this, I would
> (at worst) have a single class that would have to change in order to
> deploy on a different DB/datasource.  When I actually get around to it,
> I'm pretty sure I should be able to find a way to dynamically load some
> settings that would even eliminate that altogether.
>
> Being a newbie, maybe somebody else has a better solution.  If so, I'd
> sure be interested in it as well.
>
> gary.
>
> Justin Casp wrote:
> >Hi list,
> >I'm trying to use an auto-numbering strategy for a bean's PK, e.g.,
> > sequences on Postgres or Identity on MS SQL.  The bean's PK type is
> > Integer.  When I attempt to not set a specific value for this field in
> > ejbCreate() (assuming that the DB will assign a value for me), I get the
> > following error using Postgres:
> >11:52:09,393 ERROR [MyBean] Could not create entity
> >java.sql.SQLException: ERROR:  ExecAppend: Fail to add null value in not
> > null attribute mybeanID
> >
> >        at org.postgresql.core.QueryExecutor.execute(Unknown Source)
> >        at org.postgresql.Connection.ExecSQL(Unknown Source)
> >        at org.postgresql.jdbc2.Statement.execute(Unknown Source)
> >        at org.postgresql.jdbc2.Statement.exec
> >        at org.postgresql.jdbc2.PreparedStatement.executeUpdate(Unknown
> >Source)
> >        at
> >org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeUpdate
> >(LocalPreparedStatement.java:308) uteUpdate(Unknown Source)
> >
> >etc.
> >
> >I get a similar error using the MSSQL driver with their DB.
> >Basically, I want to know if it is possible to do this sort of thing in a
> >DB-agnostic manner (well, as much as possible, anyway- I would have to
> > assume the DB supports an auto-numbering scheme).  The Postgres exception
> > above looks like the JDBC driver might be the part having problems.
> >
> >One alternative is to use an external ID generator, similar to this
> > article: http://www.theserverside.com/patterns/thread.jsp?thread_id=4228
> >
> >But the problem with this is that the database that I'm working with is
> > not exclusively accessed by JBoss.  I have to share it with existing
> > non-java legacy apps that use the sequence/Identity feature, and changing
> > these apps is not really an option.
> >
> >I'm thinking that this is a fairly common problem, but I couldn't find
> > much on the web specific to JBoss or JDBC/Postgres/MSSQL.
> >
> >Any tips on how to resolve this issue would be much appreciated.
> >Thanks!
> >Justin
> >
> >
> >_______________________________________________________________
> >
> >Sponsored by:
> >ThinkGeek at http://www.ThinkGeek.com/
> >_______________________________________________
> >JBoss-user mailing list
> >[EMAIL PROTECTED]
> >https://lists.sourceforge.net/lists/listinfo/jboss-user
>
> _______________________________________________________________
>
> Sponsored by:
> ThinkGeek at http://www.ThinkGeek.com/
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user


----------------------------------------------------------------------------
                   Bringing you mounds of caffeinated joy
                   >>>     http://thinkgeek.com/sf    <<<

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to