Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / January 2004

Tip: Looking for answers? Try searching our database.

EJB CMP : generating an ID

Thread view: 
Bernard Koninckx - 16 Jan 2004 11:48 GMT
Hello everybody,

I would like to create a custom number identifier for a CMP bean. I would
like just work with a sequencial number begining to 1 an step by 1.

How can I do implement that ? I would like also when the EJB server crashes,
thant this sequence is automoticaly set to the max number + 1.

Thanks everybody
Ashton - 16 Jan 2004 13:02 GMT
> I would like to create a custom number identifier for a CMP bean. I would
> like just work with a sequencial number begining to 1 an step by 1.

Many times you can do this in the database itself.  (MySQL:
AUTO_INCREMENT; PostgreSQL: serial)  Which database are you using?
Bernard Koninckx - 16 Jan 2004 13:23 GMT
I'm using a MySQL DataBase at this time.
And how can I get the id generated by the database for the current bean.

Thanks

Bernard

> > I would like to create a custom number identifier for a CMP bean. I would
> > like just work with a sequencial number begining to 1 an step by 1.
>
> Many times you can do this in the database itself.  (MySQL:
> AUTO_INCREMENT; PostgreSQL: serial)  Which database are you using?
Ashton - 16 Jan 2004 14:09 GMT
> I'm using a MySQL DataBase at this time.
> And how can I get the id generated by the database for the current bean.

I don't remember if you're using JBoss....  I am and the trick with it
is to use an entity-command.  If you look in standardjbosscmp-jdbc.xml,
there's something defined as "mysql-get-generated-keys".  (I'm using the
equivalent PostgreSQL version at the moment.)

I assume other servers have other ways of dealing with it.
Bernard Koninckx - 16 Jan 2004 14:24 GMT
Thank you !

Yes I use the jBoss Server ...

I'm going to try your solution.

And I repost a message if I have any other problems

Bernard

> > I'm using a MySQL DataBase at this time.
> > And how can I get the id generated by the database for the current bean.
[quoted text clipped - 5 lines]
>
> I assume other servers have other ways of dealing with it.
Bernard Koninckx - 16 Jan 2004 14:34 GMT
Hello,

And how can I do if I prefer to stay independent from the platform server ?

Bernard

> > I'm using a MySQL DataBase at this time.
> > And how can I get the id generated by the database for the current bean.
[quoted text clipped - 5 lines]
>
> I assume other servers have other ways of dealing with it.
Jens Kutschke - 16 Jan 2004 14:48 GMT
> And how can I do if I prefer to stay independent from the platform server ?
>
> Bernard

I don't know if it is a MUST for your project to have numeric ids. If you
can use strings, look at these resources:

http://www.google.com/search?q=java+UUID+generation

Bye,
Jens

--
Jens Kutschke
http://www.j-dimension.com
Bernard Koninckx - 16 Jan 2004 16:29 GMT
It's a very long key ...
I prefere to use an Integer or a Double field into my database.

Bernard

> > And how can I do if I prefer to stay independent from the platform server
> ?
[quoted text clipped - 12 lines]
> Jens Kutschke
> http://www.j-dimension.com
Ashton - 16 Jan 2004 21:00 GMT
> And how can I do if I prefer to stay independent from the platform server ?

Well, you could create the number as a field in some table, load it at
startup into an application-scope bean and have a single instance of
that bean manage the number.  (If you're worried about crashes, you
could validate it at startup as well.)

If you can get away with non-sequential numbers, you can base your key
on a startup timestamp and then you don't have to worry about
validations after crashes.

But, part of the logic for having deployment descriptors is to allow
deployment variables to change.  If you are using any files called
jboss*.xml, then you're already not completely independent from the
server.
Bernard Koninckx - 19 Jan 2004 11:28 GMT
Please,

Could you send me a sample code to illustrate the first method, including
the ejb-jar, ... needed ?

Thank you very much

Bernard

> > And how can I do if I prefer to stay independent from the platform server ?
>
[quoted text clipped - 11 lines]
> jboss*.xml, then you're already not completely independent from the
> server.
Bernard Koninckx - 22 Jan 2004 11:16 GMT
Hi everbody,

It's possible to have some code to illustarte your solutions ?

Thank you all

Bernard Koninckx

> Hello everybody,
>
[quoted text clipped - 5 lines]
>
> Thanks everybody


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.