Automatic primary key generation for pointbase

Hello friends,
I was wondering whether it is possible to automatically generate primary keys for a pointbase database. Just like the SQL Server pointbase also has a indentity property. I have used weblogic builder to specify automatic key generation. Through the pointbase console I can see that all the columns for all the tables are marked as nullable except the primary key columns. However when I try to insert data into the database using ejb. I get the exception :
javax.ejb.EJBException: EJB Exception:: java.sql.SQLException: Data exception -- null value not allowed. .
     at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
     at com.pointbase.net.netJDBCPrimitives.handlePrimitiveResponse(Unknown Source)
     at com.pointbase.net.netJDBCPreparedStatement.executeUpdate(Unknown Source)
     at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:94)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.__WL_create(DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.java:3177)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.ejbPostCreate(DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.java:3094)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at weblogic.ejb20.manager.DBManager.create(DBManager.java:1151)
     at weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:1100)
     at weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:171)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1_LocalHomeImpl.create(DirectoryItem_lh4yf1_LocalHomeImpl.java:94)
     at yellowpages.web.controller.AddEntryAction.execute(Unknown Source)
     at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
     at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
     at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
     at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
     at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
     at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
     at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
; nested exception is: java.sql.SQLException: Data exception -- null value not allowed. .
java.sql.SQLException: Data exception -- null value not allowed. .
     at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
     at com.pointbase.net.netJDBCPrimitives.handlePrimitiveResponse(Unknown Source)
     at com.pointbase.net.netJDBCPreparedStatement.executeUpdate(Unknown Source)
     at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:94)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.__WL_create(DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.java:3177)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.ejbPostCreate(DirectoryItem_lh4yf1__WebLogic_CMP_RDBMS.java:3094)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at weblogic.ejb20.manager.DBManager.create(DBManager.java:1151)
     at weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:1100)
     at weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:171)
     at yellowpages.ejb.DirectoryItem.DirectoryItem_lh4yf1_LocalHomeImpl.create(DirectoryItem_lh4yf1_LocalHomeImpl.java:94)
     at yellowpages.web.controller.AddEntryAction.execute(Unknown Source)
     at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
     at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
     at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
     at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
     at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
     at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
     at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

I am not sure whether I understand your question.
The 'NamedSequenceTable' method is independent of data base type.
<from-docs>
Create a table named SEQUENCE to hold the current primary key value. The
table consists of a single row with a single column, as defined by the
following statement:
CREATE table_name (SEQUENCE int)
INSERT into table_name VALUES (0)
</from-docs>
Then, you can add the following in the DD -
<automatic-key-generation>
<generator-type>NamedSequenceTable</generator-type>
<generator_name>table_name</generator-name>
<key-cache-size>100</key-cache-size>
</automatic-key-generation>
The PK type should be set to java.lang.Integer or java.lang.Long
--Sathish
<Panduranga Swamy> wrote in message news:[email protected]..
Hi,
With named sequecne table,I am able to develop the application. What I
wanted is Say Table 1 having Identity column as Primary key in the table
Pointbase database.
With Automatic primary key generation in Deployment descriptor, We
generally specify SQL_SERVER or Named Sequencetable for Primary key
generation.
For pointbase database, I dont know how to configure this?
Could you help me in this regard,
Thanks,
Pandu

Similar Messages

  • Primary key generation: Using CounterHome?

    I can't find any documentation that talks about automatic primary key generation support on OC4J. I noticed the article on the Orion Support page that mentions their "Counter" bean. Is this the extent of support for automatic primary key generation in OC4J? When I searched for this class in the distribution, I only found it in a demo application in JDeveloper.
    Is this something that is handled directly in the Oracle DB, which is why OC4J doesn't bother to support it?

    Sorry I wasn't specific. By "going nowhere", I meant it went to an error page on the orion site. I don't know why it couldn't find it, because when I just now searched for the article with the title you just gave, the resulting URL was identical to what you gave me originally.
    As to the "counter faq", I think I've seen that before, but I can't get to it right now (server overloaded or something). The one problem I remember with trying to pursue the "counter" solution was somewhat simple. I couldn't find the code. I didn't notice a download for the "Counter" class, and I can't find it in either the jdeveloper or oc4j distributions.
    In any case, I ended up implementing the UUID solution, based on Floyd Marinescu's example in "EJB Design Patterns". I think this will work fine for our application.
    I'd still like to know more about Orion's "Counter" solution, if there's any real code available to see.

  • Help Primary Key generation

    According to article "Generating Primary Key Values in CMP Beans" (http://www.netbeans.org/kb/41/generated-primary-keys.html) you can specifiy automatic primary key generation.
    The following fragment describes a key issue when you have a existing database schema.
    If the database schema is not created during deployment, the primary key column in the mapped table must be of type NUMERIC with a precision of 19 or more, and must not be mapped to any CMP field. The Sun Java System Application Server generates unique values for the primary key column at runtime.
    In the used sample for how to set up a MySql database the creation of the customer table must be as follows:
    CREATE TABLE customer (
    id BIGINT(19) NOT NULL auto_increment, -- this column will be automat. generated
    lastName varchar(25) NOT NULL,
    firstName varchar(30) default NULL,
    PRIMARY KEY (id));
    My question is:
    Is it nescesary to have the field id to be decleared auto incremented?
    The first fragment says that the AS will create new values for the primary key. Or does the generation of primary keys only work if the pk field in the database table is auto incremented by the database?
    Please help. Thanks!
    Johan.

    Hello Johan,
    no, as i remember it does not work if you specify the id column as auto_increment. The J2EE bean container does manage the generation of the primary key, so the database must have a column type int(19) or bigint and primary key, not more.
    Hope this helps, more information is in the J2EE documentation from Sun, page 1012.
    Kind regards,
    marc.

  • Primary key generation

    How do use primary keys generated by database within entity bean?

    DBMS primary key generation uses a set of deployment descriptors that
    are specified at compile time to generate container code which is used
    in conjunction with a supported database to provide key generation
    support. Specify the name of the supported DBMS and the generator name,
    if required by the database. Generated primary key support for Oracle
    databases use Oracle's SEQUENCE. Once the SEQUENCE already exists in the
    database, you specify automatic key generation in the XML deployment
    descriptors. In the weblogic-cmp-rdbms-jar.xml file
    <automatic-key-generation>
    <generator-type>ORACLE</generator-type>
    <generator_name>test_sequence</generator-name>
    <key-cache-size>10</key-cache-size>
    </automatic-key-generator>
    You need to specify the name of the ORACLE SEQUENCE to be used in the
    generator-name element. If the ORACLE SEQUENCE was created with an
    INCREMENT value, then you must specify a key-cache-size. This value must
    match the Oracle SEQUENCE INCREMENT value.
    Owen wrote:
    How do use primary keys generated by database within entity bean?

  • Error in primary key generation

    Hello,
    I am using Postgresql database with jboss. I am using sequence block pattern for generating automatic primary key using source code provided by ejbdesignpattern book. but when i use transaction attribute of RequiresNew for method getValueAfterIncrementingBy I get following exception. excpetion disappear when transaction attribute is changed to Required but book recommends using RequiresNew attribute for the mehtod
    can sombody tell y this exception is being raised and workaround.
    15:57:23,507 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=c40//
    1, BranchQual=] timed out. status=STATUS_ACTIVE
    15:57:23,707 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=c40//
    2, BranchQual=] timed out. status=STATUS_ACTIVE
    15:57:23,707 WARN [BeanLock] wait() interrupted in txLock, possibly a timeout
    15:57:23,707 ERROR [BeanLock] Thread[RMI TCP Connection(2)-192.168.0.46,5,RMI Ru
    ntime]Saw rolled back tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=c40//2,
    BranchQual=] waiting for txLock
    15:57:23,707 WARN [TxCapsule] Lock contention, tx=XidImpl [FormatId=257, Global
    Id=c40//2, BranchQual=]
    15:57:23,727 ERROR [LogInterceptor] RuntimeException:
    java.lang.RuntimeException: Transaction marked for rollback, possibly a timeout
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.waitForTx(QueuedP
    essimisticEJBLock.java:339)
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.doSchedule(Queued
    PessimisticEJBLock.java:211)
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.schedule(QueuedPe
    ssimisticEJBLock.java:159)
    at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
    tor.java:103)
    at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
    Interceptor.java:69)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
    rceptor.java:107)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
    torCMT.java:291)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
    8)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
    java:130)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
    at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
    at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
    lContainerInvoker.java:301)
    at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
    at $Proxy34.getValueAfterIncrementingBy(Unknown Source)
    at com.gmi.mportal.SequenceSessionBean.getNextSequenceNumber(SequenceSes
    sionBean.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
    tatelessSessionContainer.java:660)
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
    ke(CachedConnectionInterceptor.java:186)
    at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
    elessSessionInstanceInterceptor.java:77)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
    rceptor.java:107)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
    torCMT.java:237)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
    8)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
    java:130)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
    at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
    ner.java:313)
    at org.jboss.ejb.Container.invoke(Container.java:738)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
    at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
    383)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
    at sun.rmi.transport.Transport$1.run(Transport.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
    60)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
    .java:701)
    at java.lang.Thread.run(Thread.java:536)
    15:57:23,747 ERROR [LogInterceptor] EJBException, causedBy:
    java.lang.RuntimeException: Transaction marked for rollback, possibly a timeout
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.waitForTx(QueuedP
    essimisticEJBLock.java:339)
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.doSchedule(Queued
    PessimisticEJBLock.java:211)
    at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.schedule(QueuedPe
    ssimisticEJBLock.java:159)
    at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
    tor.java:103)
    at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
    Interceptor.java:69)
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
    rceptor.java:107)
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
    torCMT.java:291)
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
    8)
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
    java:130)
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
    at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
    at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
    lContainerInvoker.java:301)
    at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
    at $Proxy34.getValueAfterIncrementingBy(Unknown Source)
    at com.gmi.mportal.SequenceSessionBean.getNextSequenceNumber(SequenceSes
    sionBean.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)

    I'm experiencing the exact same problem.
    I do have a piece of information to add, though.
    This problem only occurs when I run the code (generating a PK for a given table) the FIRST time. Once a row exists in the sequence table for a table, the code works.
    On the first run, the problem occurs after the row is inserted into the table. If the row already exists, you're all set.
    Still a problem, but at least you can work around it by prepopulating your sequence table.
    --- Matt

  • ADF BC Primary key generation with SQL Server DB

    Hi,
    I am using ADF 11.1.1.6 to develop a small application that will do some very basic CRUD operations on a SQL Server DB.
    I read through http://www.oracle.com/technetwork/developer-tools/jdev/multidatabaseapp-085183.html before I'm starting to implement the Entity objects.
    This document describes a way to do primary key generation using a table created in the DB and instructs to create an application connection to the Database :
    +2. Create a Connection to the Table+
    In your application, create a database connection named ROWIDAM_DB that points to the database containing your S_ROW_ID table. Alternatively, edit your BC project's properties and add the following Java option to the project's run configuration:
    -Djbo.rowid_am_conn_name= appconnection
    where appconnection is the name of a database connection that points to the S_ROW_ID table.
    My question is how do we do this when we mve to a production environment ?
    Also I'll be interested to hear if anyone has any pointers for developing ADF apps with SQL Server. (gotchas, performance pitfalls etc. )
    -Jeevan
    Upadte : This is SQL Server 2005
    Edited by: Jeevan Joseph on May 2, 2012 9:04 AM

    my apologies to everyone ... This should have been very simple. I just need to provide the config in my AM configuration(bc4j.xml)
    jbo.rowid_am_conn_name* should be set to the connection name you create. For production deployments, theres a similar
    jbo.rowid_am_datasource_name* that should work just fine (though I havent tried if it has any hiccups).
    I'd like to point out one thing though, for whoever might stumble upon this thread and find it useful later on...
    After I did the steps above, everything seemed to work when I tested the app from the AM tester. But when I built a UI for it in ADF Faces, I started getting an exception on Create/CreateInsert :
    java.lang.ClassCastException: com.microsoft.sqlserver.jdbc.SQLServerConnection cannot be cast to oracle.jdbc.OracleConnection
         at oracle.jbo.server.OracleSQLBuilderImpl.setSessionTimeZone(OracleSQLBuilderImpl.java:5533)
         at oracle.jbo.server.DBTransactionImpl.refreshConnectionMetadata(DBTransactionImpl.java:5311)
         at oracle.jbo.server.DBTransactionImpl.initTransaction(DBTransactionImpl.java:1194)
         at oracle.jbo.server.DBTransactionImpl.initTxn(DBTransactionImpl.java:6826)
         at oracle.jbo.server.DBTransactionImpl2.connect(DBTransactionImpl2.java:136)
         at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:213)The trouble is that the ADF Faces adf-config.xml overrides the AM configuration. Oracle is the default, and it overrides the SQL flavor I set when initializing the Model project.
    This was not mentioned in the original document probably because ADF faces was out of scope for that document.
    I also found this thread extremely useful, and its what reminded me of the ADF Faces AM config overrides : Re: Locking mode 'optupdate' with SQL92
    Cheers !
    Jeevan

  • Cluster DuplicateKeyExecption and primary key generation

    Hi
    I have 2 applications servers working in a cluster.
    I'm using for primary key generation The pattern "sequence blocks" taken from the book ejb design patterns.
    However when i have something like 5 threads that are trying to create new entities then i get DuplikateKeyException on the primary key. (with only 1 jboss server not in a cluster everything is fine).
    I was wondering if anybody could help me pin out the problem, following is my code:
    I estimated it might be an Isolation level problem, however i have updated the isolation level to be serializable in that way in mysql ds and the problem still happend...
    Code:
    <user-name>root</user-name>
    <password></password>
    <TransactionIsolation>TRANSACTION_SERIALIZABLE</TransactionIsolation>
    Sequence entity bean
    Code:
    import javax.ejb.*;
    abstract public class SequenceBean implements EntityBean {
    EntityContext entityContext;
    public java.lang.String ejbCreate(java.lang.String name) throws CreateException {
    setName(name);
    return null;
    public void ejbPostCreate(java.lang.String name) throws CreateException {
    setSIndex(ConfigContainer.getJMXPropertiesFacade().getSequenceSessionBeanStartIndex());
    public void ejbRemove() throws RemoveException {
    public abstract void setName(java.lang.String name);
    public abstract void setSIndex(int sIndex);
    public abstract java.lang.String getName();
    public abstract int getSIndex();
    public void ejbLoad() {
    public void ejbStore() {
    public void ejbActivate() {
    public void ejbPassivate() {
    public void unsetEntityContext() {
    this.entityContext = null;
    public void setEntityContext(EntityContext entityContext) {
    this.entityContext = entityContext;
    public int getValueAfterIncrementingBy(int blockSize) {
    this.setSIndex(this.getSIndex()+ blockSize);
    return this.getSIndex();
    sequence session bean
    Code:
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.ejb.CreateException;
    import javax.ejb.FinderException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import javax.naming.Context;
    import javax.naming.NamingException;
    import org.apache.log4j.Category;
    public class SequenceSessionBean implements SessionBean {
    SessionContext sessionContext;
    private Category _log;
    private class Entry {
    Sequence sequence;
    int last;
    private java.util.HashMap _entries = new java.util.HashMap();
    private int _blockSize;
    private int _retryCount;
    private SequenceHome _sequenceHome;
    public void ejbCreate() throws CreateException {
    _log = Category.getInstance(getClass());
    public void ejbRemove() {
    public void ejbActivate() {
    public void ejbPassivate() {
    public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
    Context namingContext = null;
    try {
    namingContext = new javax.naming.InitialContext();
    _blockSize = JMXPropertiesFacade.getInstance().getSequenceSessionBeanBlockSize();
    _retryCount = JMXPropertiesFacade.getInstance().getSequenceSessionBeanRetryCount();
    _sequenceHome = (SequenceHome) namingContext.lookup("SequenceLocalHome");
    catch (NamingException e) {
    _log.error(e.getMessage(), e);
    public void synch() throws InternalException {
    Connection connection = null;
    ResultSet resultSet = null;
    Statement statement = null;
    int maxObjectID = 0, maxUID = 0, maxShareID = 0;
    try {
    connection = MASConnectionManager.getInstance().createConnection();
    String sql = "select max(" + AlbumElementHome.FIELD_NAME_OBJECT_ID + ") maxObjectID from " + AlbumElementHome.TABLE_NAME;
    statement = connection.createStatement();
    _log.debug("SQL : " + sql);
    statement.execute(sql);
    resultSet = statement.getResultSet();
    if (resultSet.next()) {
    maxObjectID = resultSet.getInt("maxObjectID");
    _log.debug(String.valueOf(maxObjectID));
    resultSet.close();
    statement.close();
    ((Sequence) sequenceHome.findByPrimaryKey(AlbumElementHome.JNDINAME)).setSIndex(maxObjectID
    + 1);
    sql = "select max(" + UserHome.FIELD_UID + ") maxUID from " + UserHome.TABLE_NAME;
    statement = connection.createStatement();
    _log.debug("SQL : " + sql);
    statement.execute(sql);
    resultSet = statement.getResultSet();
    if (resultSet.next()) {
    maxUID = resultSet.getInt("maxUID");
    _log.debug(String.valueOf(maxUID));
    resultSet.close();
    statement.close();
    ((Sequence) sequenceHome.findByPrimaryKey(UserHome.JNDINAME)).setSIndex(maxUID + 1);
    sql = "select max(" + AlbumElementShareHome.FIELD_SHARE_ID + ") maxShareID from " + AlbumElementShareHome.TABLE_NAME;
    statement = connection.createStatement();
    _log.debug("SQL : " + sql);
    statement.execute(sql);
    resultSet = statement.getResultSet();
    if (resultSet.next()) {
    maxShareID = resultSet.getInt("maxShareID");
    _log.debug(String.valueOf(maxShareID));
    resultSet.close();
    statement.close();
    ((Sequence) sequenceHome.findByPrimaryKey(AlbumElementShareHome.JNDINAME)).setSIndex(maxShar
    eID + 1);
    } catch (SQLException e1) {
    _log.error(e1.getMessage(), e1);
    } catch (FinderException e) {
    throw new InternalException(e);
    } finally {
         try {
         if (connection != null && !connection.isClosed()) connection.close();
         } catch (SQLException e) {
         _log.error(e.getMessage(), e);
    public int getNextSequenceNumber(String name) {
    try
    Entry entry = (Entry) _entries.get(name);
    if (entry == null)
    // add an entry to the sequence table
    entry = new Entry();
    try
    entry.sequence = _sequenceHome.findByPrimaryKey(name);
    catch (javax.ejb.FinderException e)
    _log.info("can't find sequence: " + name + " trying to create it");
    // if we couldn't find it, then create it...
    entry.sequence = _sequenceHome.create(name);
    _log.info("sequence: " + name + " created");
    _entries.put(name, entry);
    if (entry.last % _blockSize == 0)
    for (int retry = 0; true; retry++)
    try
    entry.last = entry.sequence.getValueAfterIncrementingBy(_blockSize);
    break;
    catch (javax.ejb.TransactionRolledbackLocalException e)
    if (retry < _retryCount)
    // we hit a concurrency exception, so try again...
    _log.info("RETRYING");
    continue;
    else
    // we tried too many times, so fail...
    throw new javax.ejb.EJBException(e);
    return entry.last++;
    catch (javax.ejb.CreateException e)
    throw new javax.ejb.EJBException(e);
    from ejb-jar.xml
    Code:
    <container-transaction>
    <method>
    <description />
    <ejb-name>SequenceSession</ejb-name>
    <method-name>getNextSequenceNumber</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    </method-params>
    </method>
    <trans-attribute>RequiresNew</trans-attribute>
    </container-transaction>
    jboss.xml
    Code:
    <container-configurations>
    <container-configuration>
    <container-name>Standard CMP 2.x EntityBean with cache invalidation</container-name>
              <commit-option>A</commit-option>
              <cache-invalidation>True</cache-invalidation>
    </container-configuration>
    </container-configurations>
    <entity>
    <ejb-name>Sequence</ejb-name>
    <local-jndi-name>SequenceLocalHome</local-jndi-name>
    <!-- no cache for this entity bean -->
    </entity>
    anybody can help with what the problem might be?
    did i update the isolation level correctly?

    _blocksize may be returning 0                                                                                                                                                                                                                                   

  • Marinescu Primary Key Generation

    Hi
    i'm using Marinescus Primary Key Generation schema, but i'm having a problem
    As i see it in EJB Design Patterns (Marinescus Book), he uses a Hashtable to store the values so that the Bean doesn't have to access the database everytime
    My problem is that this Hashtable is not working, because each client when access the Bean, this creates a new bean (just like in the pattern) and thus there is never info on the Hashtable, thus the application has to go to the Database.
    If i put the Hashtable as static, i will have Concurrency Problems
    But my real problem is that i've seen various implementations of this pattern, and no one seems to talk about this problem
    Am i missing something ?
    I've thought maybe Marinescus uses only one static SessionBean (resolving the problem), but he create one Bean for each request also
    Thanks

    So, i found the problem
    I had the SessionBean configured as a Stateful Session Bean
    But if i change it to Stateless it starts working
    I still didn't figured out why (as no Load, Store, Passivation or Activation code exists to keep or get the Hashtable)
    So if any one could explain it to me, it would be nice :)
    Thanks

  • CDG-01141 ERROR: Module Component Table Usage ...  Table usage ... requires primary key column for referential integrity

    For some strange reason when I modified a form, (commented out some code in a when-window-activated trigger) I now get the following error.
    CDG-01141 ERROR: Module Component Table Usage GR1130A.CUSTOMER.GR_CUSTOMER.GC: Table usage GR_CUSTOMER requires primary key column for referential integrity
    I am sure this is not related to my change, but do not know what may have caused this or how to fix it.
    Anyone seen this error before? been able to fix it?
    Thanks!
    Windows 7
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Designer Version 6.5.95.4.8

    You know that Developer/Designer 6i is not certified for Windows 7, right? Also, your version is not the latest one, so you can try to install the latest patch set first.
    >Table usage GR_CUSTOMER requires primary key column for referential integrity
    Check if there is a PK in the table definition (not in the database, but in Designer).

  • Primary key constraint for index-organized tables or sorted hash cluster

    We had a few tables dropped without using cascade constraints. Now when we try to recreate the table we get an error message stating that "name already used by an existing constraint". We cannot delete the constraint because it gives us an error "ORA-25188: cannot drop/disable/defer the primary key constraint for index-organized tables or sorted hash cluster" Is there some sort of way around this? What can be done to correct this problem?

    What version of Oracle are you on?
    And have you searched for the constraint to see what it's currently attached to?
    select * from all_constraints where constraint_name = :NAME;

  • Do I need to Create Primary Key Class for Entity beans with Local interface

    Do I need to Create Primary Key Class for Entity beans with Local interface?
    I have created my entity bean with the wizard in Sun One Studio and it does not create a primary key class for you.
    I thought that the primary key class was required. My key is made up of only one field.
    Anyone know the answer.
    Jim

    u dont need to create a primary key class for a entity bean.if ur table's primary key feild(int ,float) is a built in or primitive data type,then u dont need one.But if ur table has a primary key field which is non primitive (for example StudentID,ItemID etc)then u have to create a primary key class.
    hope this helps :-)

  • APEX 4.0 -Show and able to change Primary key values for Detail

    In a Master-Detail form, is there anyway I can show and able to change/select my primary keys from a select list field? One of my primary keys on the Detail is also primary key from another table which restricts my values for this field. I was able to show the fields but I can not make changes to this field and save the changes. Is there anyway I can have both show the field and able to change field's value and save it? Please advice. Thank you very much for your help in advance.
    -Grace

    Yes AFAIK Apex (for better or worse) was designed such that the PKs are generated automatically with PL/SQL, by a trigger, or whatever other algorithm that isn't in the control of the end user. It also only seems to allow a composite PK of no more than two columns.
    My usual strategy is to:
    1. Define the PK as a number (some sort of RECORD_ID, RECORD_SEQ, whatever) and populate it via a trigger on-insert.
    2. Define the "business" PK as a separate unique index. This way the user can set and modify it to their heart's content and it also isn't limited to just two columns (if the composite key's business requirement is such that more than two columns are needed).

  • Primary key generation by insert trigger.

    I have a table and wish to automatically create a unique sequence number for use as the primary key.
    In PL/SQL I do something like this:
    create sequence personnel_seq;
    create or replace trigger personnel_insert
    before insert on personnel
    for each row
    declare seqNo NUMBER;
    begin
    select personnel_seq.NextVal into seqNo from dual;
    :new.vc_personnel_reference := seqNo;
    end personnel_insert;
    column personnel.vc_personnel_reference is the primary key of table personnel, and not null.
    What's the recommended way to do something similar in BC4J?
    At present I'm using the trigger but BC4J doesn't know it exists, and insists on a value for vc_personnel_reference being provided. It also insists on adding the primary key to the ViewObject's attributes.
    I can provide a dummy value in ViewObjectRowImpl.insertRow() but this seems cumbersome.
    Is there a better way?
    In fact can I do this kind of thing entirely in BC4J without the trigger?
    Tony.

    But be carefull with DBSequences.
    There's a "problem" because the DBSequencs is a Domain and a "domained" field is not equal to any other field.
    In that case if have an Entity with Id = 1 (where d comes out from a DbSequence) and You look for Id = n where n is a Number containing 1, You will not find Your record !!!
    As 9.0.2.; I don't know in 9.0.3.
    Bye
    Tullio

  • Database Deferred Primary Key generation

    Does anyone know how to configure 9iAS J2EE/OC4J to defer the creation of the Primary to the Database? For example, I have a table that is mapped to a CMP bean and the primary key is generated by a trigger in the database. I want the bean to use this database generated value but I can't figure out how to make it happen. I have tried setting the <prim-key-class> to java.lang.Object but that doesn't appear to be enough to get 9iAS to figure out that the primary key field is to come from the database.
    Regards,
    Nigel

    you should set in your entity object the attribute as DBSequence and then create a before insert trigger in the db table to get the pk from a sequence or so, something like:
    CREATE OR REPLACE TRIGGER trigger_name
    BEFORE INSERT
    ON table_name
    FOR EACH ROW
    begin
    select seq_name.nextval into :new.pk_id from dual;
    end;

  • CMP with Primary key generation in Oracle

    I need to know how can I from my Entity Beans use Oracle sequences to automatically create my primary key.
    I know that Weblogic lets to define with sequence to use in the deployment descriptor, but the problem is that I am using Websphere Application Server.
    Does anyone have any suggestion doing this.
    Very Thanks!!

    See if this link helps - http://theserverside.com/patterns/thread.jsp?thread_id=220

Maybe you are looking for