Composite Primary Key or Auto Increment key ?

Hi.. i have two ways for make something and don't know what's better ......
Problem : 3 tables
Client ----> ( 1,* ) Activity -----> (1,1) ActivityAccreditation
A Client it can have one or more activities, and one Activity have one ActivityAccreditation. On Client the primary key is CLIENT_ID, the two ways for generate the keys on the other tables are :
a ) On Activity the primary key is composed by CLIENT_ID and SEQUENCE_ACTIVITY ( a number than increment value by CLIENT_ID, example : CLIENT_ID = 1122 could have SEQUENCE_ACTIVITY from 1 to 3 for three activities, and CLIENT_ID = 1122 could have SEQUENCE_ACTIVITY from 1 to 4 for four activities ), and ActivityAccreditation have CLIENT_ID and SEQUENCE_ACTIVITY and ACCREDITATION_TYPE ( a code ).
b) On Activity the primary key is ACTIVITY_ID ( auto increment number ) with the CLIENT_ID like foreign key only. And on ActivityAccreditation have ACTIVITY_ACCREDITATION_ID like primary key and ACTIVITY_ID like foreign key.
The situation is than the numer of rows could to grow very much in the time ( 3.000.000 rows on ActivityAccreditation in one year and the database to be supported each five years ) and we don't know what solution is better by performance......
Tks.

I prefer the surrogate key.
I don't like composite keys as a rule because they tend to inject business logic into keys. Using surrogate keys eliminates this possibility.
For performance reasons, this means that you might want to create additional indexes on those columns to facilitate fast access. But my prejudice is to stick with surrogate keys.
I will admit that I'm not a DBA, so there are certain to be alternative views and arguments. We'll see if any of them pop up on this thread.

Similar Messages

  • MySQL Auto Increment Keys

    Is there a way to use MySQL Auto Increment Keys with Kodo?
    sean.

    Actually, I believe that the auto-increment support is in the current
    2.5.0 release (beta 2).
    -Patrick
    On Fri, 11 Apr 2003 22:11:02 -0400, Marc Prud'hommeaux wrote:
    Note that the feature isn't available in the current beta, but it will
    be available in the final release (which will be out "real soon now").
    In article <[email protected]>, Abe
    White wrote:
    I believe we've added some auto-increment support in our 2.5 beta,
    available here:
    http://solarmetric.com/Software/beta/2.5.0
    Patrick Linskey
    SolarMetric Inc.

  • Primary key column auto increment

    Hello,
    In my Azure SQL Database I noticed that weird thing is happening. I have table with primary key column with auto increment, and all works fine, on new insert that value automatically increment, but every now and then, that value, for no reason, increments
    for 1000.
    For instance i have in DB values in this order: 1, 2, 3, 4, 1001, 1002, 1003, 2004,  2005, 3001, 3002...
    Why is this happening? 

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • Retrieve new row's auto-increment key from dataprovider

    ** cross posted on SDN JSC Forum and Netbeans J2EE Nabble forum **
    I have a page that is bound to a MySQL table rowset or, alternately, a new (append()'ed) row. The row's Primary Key is a MySQL auto-increment Integer (translates to a Long.) After commit()'ing the the new row to the database, how would I then get the new row's ID (fieldname "ID")? If I refresh() the dataprovider and try to get the value an error is thrown.
    Some background: The dataprovider's backing rowset has a query parameter for the ID field. I set it to "0" if the page is creating a new row or I set it to the unique ID if the page is displaying an existing row. After the new row is committed, I need the new ID set the query parameter and synch up related rows in different tables that are keyed off the ID in this (master) table. I'd like to do this without "guessing" what the ID would be in advance as that method isn't foolproof in heavy usage.
    Additionally, it strikes me as a useful workaround if the unique ID was a UUID (mySQL UUID() function) that does not run the risk of any concurrency issues. Has anyone used this solution in VWP? How would I make the call for the underying DB (in this case MySQL, but could be anything) to generate the UUID? Is the call DB specific or is there a JDBC equivalent?
    UPDATE: never mind the GUID question, I can use the java.rmi.dgc.VMID class to autogenerate unique GUID's for this purpose. Being from a Lotus Notes background, I'm used to the power and flexibility such Unique ID's bring to the app. dev's portfolio.
    Thanks in adv. for any help .
    -Jake
    Message was edited by:
    jakeochs

    JSF together with JBoss Seam offers some real good possibilities to improve developer productivity. Right now, with JSF you can create forms where fields are persistent (saved in a database), but you have to write code to persist fields. In Notes/Domino, every field you drop in the form is automatically set to persist without writing a single piece of code. JBoss Seam aims to provide the missing glue to tie the JSF beans with business logic (EJB) and persistent layer (JPA). I think tools for Seam are still not mature. I would love to see JSC/VWB utilizing Seam. I know there is a NetBean plugin for Seam but it was written for old NetBeans (not VWP or JSC), so it doesn't work with the visual web pack where you can drag and drop JSF components.

  • Trying to create cmp correctly(auto-increment);error while running

    I am using the latest versions of Jboss(4.0.5.GA) and Lomboz(R-3.2-200610201336) along with SQL Server 2005 and Microsoft's SQL Server 2005 JDBC driver.
    Lomboz used xdoclet to create the java files based on the SQL table but it did not put anything in the DoctorBean.java file telling it that the primary key was auto-incremented.
    Using the JSP files, I can retreive data out of the database fine so I know the connection and drivers are set up properly.
    Here is the error:
    09:16:46,815 WARN  [ServiceController] Problem starting service jboss.j2ee:service=EjbModule,module=MedicalEJB.jar
    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(Unknown Source)
        at org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:197)
        at org.jboss.mx.loading.UnifiedLoaderRepository3.loadClassFromClassLoader(UnifiedLoaderRepository3.java:277)
        at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:284)
        at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:511)
        at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.jboss.util.loading.DelegatingClassLoader.loadClass(DelegatingClassLoader.java:89)
        at org.jboss.mx.loading.LoaderRepositoryClassLoader.loadClass(LoaderRepositoryClassLoader.java:90)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.jboss.util.loading.DelegatingClassLoader.loadClass(DelegatingClassLoader.java:89)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityCommandMetaData.<init>(JDBCEntityCommandMetaData.java:73)
        at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData.<init>(JDBCEntityMetaData.java:952)
        at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:378)
        at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:89)
        at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:736)
        at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBCStoreManager.java:424)
        at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:368)
        at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:172)
        at org.jboss.ejb.EjbModule.startService(EjbModule.java:414)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
        at $Proxy0.start(Unknown Source)
        at org.jboss.system.ServiceController.start(ServiceController.java:417)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy25.start(Unknown Source)
        at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:662)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
        at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
        at org.jboss.ws.integration.jboss.DeployerInterceptor.start(DeployerInterceptor.java:92)
        at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
        at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy26.start(Unknown Source)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
        at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy8.deploy(Unknown Source)
        at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
        at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
        at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
        at $Proxy0.start(Unknown Source)
        at org.jboss.system.ServiceController.start(ServiceController.java:417)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy4.start(Unknown Source)
        at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
        at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
        at $Proxy5.deploy(Unknown Source)
        at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
        at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
        at org.jboss.Main.boot(Main.java:200)
        at org.jboss.Main$1.run(Main.java:490)
        at java.lang.Thread.run(Unknown Source)
    09:16:46,862 INFO  [EJBDeployer] Deployed: file:/C:/java/jboss-4.0.5.GA/server/default/deploy/MedicalEJB.jar
    09:16:46,987 INFO  [TomcatDeployer] deploy, ctxPath=/MedicalWeb, warUrl=.../tmp/deploy/tmp63256MedicalWeb-exp.war/
    09:16:47,315 INFO  [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
    09:16:47,503 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
    --- MBeans waiting for other MBeans ---
    ObjectName: jboss.j2ee:service=EjbModule,module=MedicalEJB.jar
      State: FAILED
      Reason: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
    ObjectName: jboss.j2ee:service=EjbModule,module=MedicalEJB.jar
      State: FAILED
      Reason: java.lang.StringIndexOutOfBoundsException: String index out of range: 01Simple Doctor table:
    CREATE TABLE [dbo].[Doctors](
        [DoctorId] [int] IDENTITY(1,1) NOT NULL,
        [firstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [lastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    CONSTRAINT [PK_Doctors] PRIMARY KEY CLUSTERED
        [DoctorId] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]Most of DoctorBean.java was createded automatically with xdoclet, I created these items manually but with no success:
    * @jboss.entity-command
    * name="mssql-get-generated-keys"
    * @jboss.unknown-pk
    * class="java.lang.Integer"
    * column-name="doctorid"
    * field-name="doctorid"
    * jdbc-type="INTEGER"
    * sql-type="int"
    * auto-increment="true"DoctorBean.java:
    package com.bdintegrations.MedicalApp.EJB;
    import java.rmi.RemoteException;
    import javax.ejb.EJBException;
    import javax.ejb.EntityContext;
    import javax.ejb.RemoveException;
    * <!-- begin-xdoclet-definition -->
    * @ejb.bean name="Doctor"
    *    jndi-name="Doctor"
    *    type="CMP"
    *  primkey-field="doctorid"
    *  schema="DoctorSCHEMA"
    *  cmp-version="2.x"
    *  @ejb.persistence
    *   table-name="dbo.Doctors"
    * @ejb.finder
    *    query="SELECT OBJECT(a) FROM DoctorSCHEMA as a" 
    *    signature="java.util.Collection findAll()" 
    * @ejb.pk
    *  class="java.lang.Object"
    *  generate="false"
    * @jboss.entity-command
    * name="mssql-get-generated-keys"
    * @jboss.unknown-pk
    * class="java.lang.Integer"
    * column-name="doctorid"
    * field-name="doctorid"
    * jdbc-type="INTEGER"
    * sql-type="int"
    * auto-increment="true"
    * @jboss.persistence
    * datasource="java:/MSSQLDS"
    * datasource-mapping="MS SQLSERVER2005"
    * table-name="dbo.Doctors"
    * create-table="false" remove-table="false"
    * alter-table="false"
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract class DoctorBean implements javax.ejb.EntityBean {
         * <!-- begin-user-doc -->
         * The  ejbCreate method.
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.create-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public java.lang.Object ejbCreate(String firstName, String lastName) throws javax.ejb.CreateException {
            setFirstname(firstName);
            setLastname(lastName);
            return null;
            // end-user-code
         * <!-- begin-user-doc -->
         * The container invokes this method immediately after it calls ejbCreate.
         * <!-- end-user-doc -->
         * @generated
        public void ejbPostCreate() throws javax.ejb.CreateException {
            // begin-user-code
            // end-user-code
         * <!-- begin-user-doc -->
         * CMP Field doctorid
         * Returns the doctorid
         * @return the doctorid
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.persistent-field
         * @ejb.persistence
         *    column-name="DoctorId"
         *     jdbc-type="INTEGER"
         *     sql-type="int identity"
         *     read-only="false"
         * @ejb.pk-field
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract java.lang.Integer getDoctorid();
         * <!-- begin-user-doc -->
         * Sets the doctorid
         * @param java.lang.Integer the new doctorid value
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract void setDoctorid(java.lang.Integer doctorid);
         * <!-- begin-user-doc -->
         * CMP Field firstname
         * Returns the firstname
         * @return the firstname
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.persistent-field
         * @ejb.persistence
         *    column-name="firstName"
         *     jdbc-type="VARCHAR"
         *     sql-type="varchar"
         *     read-only="false"
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract java.lang.String getFirstname();
         * <!-- begin-user-doc -->
         * Sets the firstname
         * @param java.lang.String the new firstname value
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract void setFirstname(java.lang.String firstname);
         * <!-- begin-user-doc -->
         * CMP Field lastname
         * Returns the lastname
         * @return the lastname
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.persistent-field
         * @ejb.persistence
         *    column-name="lastName"
         *     jdbc-type="VARCHAR"
         *     sql-type="varchar"
         *     read-only="false"
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract java.lang.String getLastname();
         * <!-- begin-user-doc -->
         * Sets the lastname
         * @param java.lang.String the new lastname value
         * <!-- end-user-doc -->
         * <!-- begin-xdoclet-definition -->
         * @ejb.interface-method
         * <!-- end-xdoclet-definition -->
         * @generated
        public abstract void setLastname(java.lang.String lastname);
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#ejbActivate()
        public void ejbActivate() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#ejbLoad()
        public void ejbLoad() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#ejbPassivate()
        public void ejbPassivate() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#ejbRemove()
        public void ejbRemove() throws RemoveException, EJBException,
                RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#ejbStore()
        public void ejbStore() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
        public void setEntityContext(EntityContext arg0) throws EJBException,
                RemoteException {
            // TODO Auto-generated method stub
        /* (non-Javadoc)
         * @see javax.ejb.EntityBean#unsetEntityContext()
        public void unsetEntityContext() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
        public DoctorBean() {
            // TODO Auto-generated constructor stub
    }JSP client page snippet:
    <%
    DoctorHome home = DoctorUtil.getHome();
    Doctor doctor = home.create("Jon","Smith");
    %>
    <%=doctor.getDoctorid() %>thanks

    Nevermind.. no one bothered to inform the developer that the path to the collection AND the path to the directory that the collection is for are different on this other server.
    Fixed.

  • Auto increment with collection is not working

    I am using KODO 3.0 with MYSQL 4.0.16. I have created two JDO object as
    follows
    BankAccount contains a collection of Contacts object. My metadata looks
    like this
    <class name="BankAccount">
    <field name="contacts">
    <collection element-type="Contacts"/>
    <extension vendor-name="kodo" key="element-dependent"
    value="true"/>
    </field>
    </class>
    <class name="Contacts" objectid-class="Contacts$contactId">
    <field name="contactId" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-auto-increment"
    value="true"/>
    </field>
    </class>
    There is no problem in the persisting of BankAccount object and adding
    Contacts to it, but Contacts collation is not retrieved along with parent
    object. In the database join table, the contact Id value it is always set
    to null.
    Things are working well with out contact id in Contacts.
    Can anyone help?
    Regards,
    dharmi

    Set the following property:
    kodo.jdbc.AutoIncrementConstraints: true
    Described here:
    http://www.solarmetric.com/Software/Documentation/latest/docs/ref_guide_pc_oid.html#ref_guide_pc_oid_pkgen_autoinc

  • Cmp auto increment

    I write a bean.
    It has id field which must increment auto.
    I use j2ee. how can i do this.
    Thanks

    Hi Ugur,
    Which Server are you using ? Coz I was just going
    g through weblogic and if you are deploying your bean
    in weblogic , it can be mentioned in the descriptor
    that the pry key os auto increment If i use string as my primary key??? as P1, P2 etc????
    .hence that wont be
    created while creating the record, even though it
    would be mapped to the table column.
    And also you havent replied about the bean that you
    plan to use.Please let me know your idea.
    Patidar..would reply to your question a bit
    later..sorry bout that :-(
    thx.

  • HSQL DB Identity & Auto Increment

    We are trying to write records to this table:
    create table location_groups
    group_id identity
    ,jdoversion integer
    ,jdoclass varchar(255) default 'path.impl.LocationGroup' not null
    ,group_name varchar(100) not null
    ,group_parent_id integer
    Package.jdo is:
    <package name="path">
    <class name="LocationComponent">
    </class>
    </package>
    <package name="path.impl">
    <class name="LocationGroup" persistence-capable-superclass="path.LocationComponent">
    <!--<extension vendor-name="kodo" key="jdbc-field-map" value="one-one"/>-->
    <extension vendor-name="kodo" key="jdbc-auto-increment" value="true"/>
    <field name="children" persistence-modifier="persistent" default-fetch-group="true">
    <collection element-type="path.impl.Location"/>
    </field>
    </class>
    and package.mapping is:
    <package name="path">
    <class name="LocationComponent">
    <jdbc-class-map type="horizontal"/>
    </class>
    </package>
    <package name="path.impl">
    <class name="LocationGroup">
    <jdbc-class-map type="base" pk-column="GROUP_ID" table="LOCATION_GROUPS"/>
    <jdbc-version-ind type="version-number" column="JDOVERSION"/>
    <jdbc-class-ind type="in-class-name" column="JDOCLASS"/>
    <field name="path.LocationComponent.name">
    <jdbc-field-map type="value" column="GROUP_NAME"/>
    </field>
    <field name="children">
    <jdbc-field-map type="one-many" table="LOCATIONS" ref-column.GROUP_ID="GROUP_PARENT_ID"/>
    </field>
    </class>
    </package>
    I have tried all manner of configurations but the error remains the same:
    25-Apr-2008 16:05:24 com.ea.albt.infrastructure.persistence.jdo.JDODataStore BeginTransaction
    CONFIG: Starting transaction
    25-Apr-2008 16:05:24 com.ea.albt.infrastructure.persistence.jdo.JDODataStore updateObjects
    FINE: Updating object ALBT Loc1209135924484 (has not yet been persisted)
    25-Apr-2008 16:05:25 com.ea.albt.infrastructure.persistence.jdo.JDODataStore updateObjects
    WARNING: Failed to persist/update objectALBT Loc1209135924484
    kodo.util.FatalDataStoreException: Attempt to update the sequence table "JDO_SEQUENCE" failed. The sequence table is typically created when you run the mappingtool's refresh action on any datastore identity class. If you have not run the mappingtool but want to create the sequence table, run:
    java kodo.jdbc.schema.DBSequenceFactory -action add
    NestedThrowables:
    Why is Kodo trying to use the jdo_sequence table when we want it to use the HSQLdb identity field ?

    We have many users using single field identity and auto-increment together.

  • How to get auto-increment value after insert on ACCESS db?

    When you insert a new record to a table with an auto-incrementing key, how do you find the value for the row you just inserted? This works differently with different databases. I know how it's done on ORACLE and mySql.
    How does it work with ACCESS through ODBC? How about MSSQL?

    I have discovered there's a LAST aggregate function which when I've tested it gets the just inserted auto-increment, but I'm not sure if it's reliable. You have to do:
    SELECT LAST(index-field) FROM table
    That ought to be faster than MAX, which I've noticed some people use. Persumable LAST will get the value from the last row in the table's natural order.
    In fact an auto-increment field has no business filling in missing slots since the main point is a a foreign key in other tables and a foreign key pointing to a deleted table row ought to be invalidated, not point to some unrelated successor record.
    I could use a separate table as a source of counters, of course, though that's one more call. In either case I'm worried about thread safety. In Oracle there are special sequence objects for this purpose which are incremented and read atomically. I'm not sure if the access driver transaction handling works adequately.
    Perhaps the safest approach might be to use a separate sequencer table and Java sychronisation to serialise access to each row in the sequencer table (assuming all the access is from the same app).

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • CMP with auto-increment primary key.Please help

    Hi all,
    I new with EJB technology so please bear with me.
    Env: 2k Server, SQL 2k Server
    Sun One(Forte EE) to develop and deploy CMP
    I got the servlet to load the data from CMP's business mehods
    is fine. Calling the findPrimaryKey is OK too. Even when I try to insert the row into DB is OK. At this time I make key PK is int AND NOT
    AUTO INCREMENT everything is OK. In the ejbCreate method
    I called setPK, setName ...It's fine.
    The problem comes when I try to make the PK(still int) to be auto-increment field.In ejbCreate not call setPK because of in SunOne IDE, under the J2EE RI tab of EJB Module property, the Auto generate SQL I set to false so that I can
    modify the SQL statement under SQL Deployment.createRow not taking the PK. I thought that will do it but it doesnot like it at all (I got Exception with transaction rollback)I just want to insert a single row with ID and name that's all.
    Then I changed the SQL statment take PK and changed the Auto Generate SQL to True and in ejbCreate the PK as one of the args and called setPK this time with null object. It doesn't like neither.(Exception Cannot set the primary key with null. That is reasonable.)
    I thought using EJB fast and clean technique would help developer to develop application with easiness.
    So I realy stuck with this, I wonder ejb 2.0 support for auto increment at all because I would like to take advantage of the auto increment feature of the DB without writing the PrimaryKeySequence generator at all.
    Am I missing something with this? May be just config thing to tell
    that my PK is auto-increment field so that when the ejbCreate called it knows not taking the PK or even not asking to call setPK in ejbCreate.
    Any help would appreciated.

    Check out this thread, there's a bunch of good info:
    http://www.theserverside.com/patterns/thread.jsp?thread_id=4976

  • Utilizing auto-increment/identity fields for primary key with "application" identity

    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?

    To the best of my knowledge, you cannot use auto-increment. Due to the
    differences in the way that identities are generated at the datastore
    (upon insert) vs. JDO (upon makePersistent), this feature of SQLServer is
    not supported yet.
    However, we do provide a variety of other ways of generating identity
    which may provide a closer fit to what you want, and
    our users may have some experience in solving your problem.
    On Tue, 28 Jan 2003 09:56:08 +0000, Sean Ryan wrote:
    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?--
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • DB Adapter - PostgreSQL - Primary key - auto increment handling

    Hi,
    I have to connect to a PostgreSQL DB. I have a table in which has a primary key called seq_id. This seq_id is being incremented using a sequence.
    I have to configure the DB adapter for this table. The problem is that while creating the adapter it does not allow me to deselect the primary key (seq_id). Because of this I have to supply a value for the seq_id while inseting the data using the adapter. But this defeats the purpose of sequence (auto increment).
    Is there a way to get around this and to avoid specifying the value for seq_id while using the DB Adapter and let it get inserted using the sequence of the DB?
    Thanks,
    Sanjay

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • Auto Increment of primary key value in jdeveloper.

    hi all,
    i have one table with one primary key.
    i want to increment that primary key when ever i go for CreateInsert or create operation in JSF page.
    i have tried with db sequence value type, but i was not able to achieve my condition. in DB Sequence i got error like cannot convert java.class.string to java.class.dbsequence.
    can any one suggest me in this to achieve my condition.
    regards,
    M vijayalakshmi.

    hi all,
    from this i found the simple method to achive the auto increment of primary key.
    http://www.techartifact.com/blogs/2012/10/adding-number-for-primary-key-in-oracle-adf-using-groovy-by-sequence.html#ixzz2EeU9CWo6
    in this am facing an one small issue.
    intial value of the primary key is 1.
    for this value i have entered the row of data.
    again i have clicked on the create button.
    then the value of the primary key has increased to 2.
    for this value i didnt entered the row of data to databse.
    just i closed the browser.
    if i run the run page again, the value of primary key is 3.
    my requirment is i shd get the value of primary key is "2".
    the increment shd happen the maxi value present in the primary key of the table.
    can any one help me in this how to achive this.
    thanks in advance.
    regards,
    M vijayalakshmi.

  • Primary key violation exception in auto increment column

    Hi All,
    I am facing one issue in Multi threaded environment.
    I am getting Primary key violation exception in auto increment column. I have a table and the primary key is the auto increment column, and I have a trigger which is populating this column.
    5 threads are running and inserting the data in the table and throwing Primary key violation exception randomly.
    create table example (
    id number not null,
    name varchar2(30)
    alter table example
    add constraint PK1example primary key (id);
    create sequence example_id_seq start with 1 increment by 1;
    create or replace trigger example_insert
    before insert on example
    for each row
    begin
    select example_id_seq.nextval into :new.id from dual;
    end;
    Any idea how to handle auto increment column(trigger) in Multi threaded environment??
    Thanks,

    user13566109 wrote:
    Thanks All,
    Problem was in approach; removed the trigger and placed a seq.nextval in insert query. It has resolved the issue.I very much suspect that that was not the issue.
    The trigger would execute for each insertion and the nextval would have been unique for each insertion (that's how sequences work in oracle), so that wouldn't have been causing duplicates.
    I suspect, more likely, that you had some other code somewhere that was using another sequence or some other method of generating the keys that was also inserting into the same table, so there was a conflict in the sources of the sequences being generated.
    The way you showed you had coded above, was a perfectly normal way to assign primary keys from a sequence, and is not a problem in a multi user/threaded environment.

Maybe you are looking for

  • How Exactly Are You 'Meant' To Log Onto BT Wifi?

    Can someone tell me what exactly are you meant to use to log in to a hotspot ?  Is it the BT ID/Password you access your online customer account with?  Is it the @btinternet.com with the same or different password?  Is it something else? We got BT In

  • Using an imac G3 as second monitor for intel imac

    I just purchased a 20 inch intel imac and was curious if I could use my old imac G3 as the second monitor. I already have the DVI to VGA adapter to use in the mini DVI port on the intel imac. Is there an adapter that I can use to plug this cable into

  • Apple TV Screensaver Interrupts Movies

    I've had my Apple TV2 for over a year now, and this behavior only just started happening. I'll be watching a movie streaming from Netflix, and suddenly the screen fades to black, making me think the scene has done this intentionally, but if I leave i

  • EMAIL?  NOT!

    I ahve not been able to get e-mail down loaded (or sent from the phone) for at least a day on my (yes, it is old) blackberry.  Text comes through fine.  Have reset password, done the on off battery in battery out dance.  Nothing seems to work - and t

  • Why is my imessages not working ?

    hey i was just wondering if anyon enew why my imessages are not working they where working before and i put my ipod in to my mac and it sed you have to update it so i did and now my in meassages are not working ?