on 11-14-2004 2:58 PM
When creating a new object (or table row) it is convenient to generate a unique identifier using the database auto-increment feature (supported by databases such as MSSQL and MySQL). However, this auto-increment feature is not supported by SAP.
What is the best way to generate a unique identifier (primary key) using Java (eg. for a Entity CMP EJB)?
Can we call the ABAP number range generator from Java ? If so, how can we set this up using the Sneak Preview SAP Enterprise Portal 6.0 ?
Regards,
Alton
Hi all,
just refer to section "Automatic Primary Key Generation" in following link
http://help.sap.com/saphelp_nw04/helpdata/en/b3/b238bfd13a8f408958d70a6989d001/content.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not that complicate:
See methode getUniqueIncreasingNumber() of Interface LogicalLocking at
http://media.sdn.sap.com/html/submitted_docs/60_sp2_javadocs/j2eeengine/index.html
Regards,
Benny
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Can you send me implementation notes or code examples
> ?
No I can't.
> Also, is it possible to use
> getUniqueIncreasingNumber() outside of EJBs; for
> example, JDO, JDBC or javax.sql.rowset.CachedRowSet
> ?
Sure. This is actually part of the Locking API that is available with WebAS.
You seem to be new to java? You only have to import the Interface to your code and have the lib in your path (project properties).
If this is new to you I would advice to learn java a little deeper before continuing. Some things are really very different from ABAP. And java tutorials are legion.
Regards,
Benny
Benny,
Thanks for your lead. I got it working on "SAP Enterprise Portal 6.0 SP4 NetWeaver Developer Sneak Preview" as follows:
1) Added the following External JARs to the Java Build Path
\usr\sap\P66\JC00\j2ee\cluster\server0\bin\services\applocking\applocking.jar
\usr\sap\P66\JC00\j2ee\cluster\server0\bin\system\exception.jar
\usr\sap\P66\JC00\j2ee\cluster\server0\bin\system\frame.jar
2) Use the following code:
Context initialContext = new InitialContext();
LogicalLockingFactory lockingFactory = (LogicalLockingFactory) initialContext.lookup(LogicalLockingFactory.JNDI_NAME);
LogicalLocking locking = lockingFactory.createLogicalLocking("ObjectNameSpace","Description");
long id = locking.getUniqueIncreasingNumber();
Hi Folks,
thanks for this great post
(I used "applocking"-service now from an portal-component (after setting the right references))
but: (just to be sure) the "increasing number" increases more or less arbitrarily, right? Not like "1, 2, 3" - but just a big number increasing somehow, right?
Or am I doing something wrong? Do I have to cast the long somehow or something else?
Thanks,
Simon
Hi folks,
just for your information. If you are looking for a way to generate a Globally Unique Identifier (GUID) there's also the GUIDService on the WebAS.
import com.sap.guid.GUIDGeneratorFactory;
import com.sap.guid.IGUIDGenerator;
...
IGUIDGenerator generator = GUIDGeneratorFactory.getInstance().createGUIDGenerator();
String guid = generator.createGUID().toHexString();
Just to let you know
Matthias
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.