persistence@glassfish.java.net

Re: specifying sequence starting number in DescriptorCustomizer

From: sudhakar <sudhakar_at_co.brazos.tx.us>
Date: Thu, 25 Oct 2007 16:54:17 -0500

Here is what I have now:

My entity class is as follows:

[begin code]
public class Owner extends ModelBase {

    @Column(name = "number")
    @SequenceGenerator(name = "OWNER_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"OWNER_SEQ")
    private int number;
}
[end code]

My SequenceCustomizer as as follows

[begin code]
public class SequenceCustomizer implements SessionCustomizer {
    public void customize(Session session) throws Exception {
        session.getDatasourcePlatform().getSequence("OWNER_SEQ")
                .setInitialValue(10001);
    }
}
[end code]

My persistence.xml has this
[begin code]
<property name="toplink.session.customizer"
value="brazos.permit.ejb.domain.internal.SequenceCustomizer" />
[end code]

Deployment fails with a NullPointerException in the getSequence() line
in SequenceCustomizer above.

Here is the stacktrace from the server.log file in glassfish when I
deploy the EJB application jar

[begin log]
----------------------------------------------------------------

[#|2007-10-25T16:46:17.988-0500|CONFIG|sun-appserver9.1|oracle.toplink.essentials.session.file:/E:/Java/glassfish/domains/domain1/applications/j2ee-modules/brazos.permit.ejb-1.0.0.v20071026/-permitPU.ejb_or_metadata|_ThreadID=17;_ThreadName=Timer-5;|The
primary key column name for the mapping element [private
brazos.permit.ejb.domain.User
brazos.permit.ejb.domain.ModelBase.createdByUser] is being defaulted to:
sys_id.|#]

    at java.lang.reflect.Method.invoke(Method.java:597)
    at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:375)
    at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:358)
    at
com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:464)
    at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
    at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
    at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
    at $Proxy1.invoke(Unknown Source)
    at
com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
    at
com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174)
    at
com.sun.enterprise.deployment.autodeploy.AutoDeployer.invokeDeploymentService(AutoDeployer.java:564)
    at
com.sun.enterprise.deployment.autodeploy.AutoDeployer.deployJavaEEArchive(AutoDeployer.java:545)
    at
com.sun.enterprise.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:492)
    at
com.sun.enterprise.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:267)
    at
com.sun.enterprise.deployment.autodeploy.AutoDeployControllerImpl$AutoDeployTask.run(AutoDeployControllerImpl.java:374)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.NullPointerException
    at
brazos.permit.ejb.domain.internal.SequenceCustomizer.customize(SequenceCustomizer.java:15)
    at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.processSessionCustomizer(EntityManagerSetupImpl.java:990)
    ... 46 more
|#]

[#|2007-10-25T16:46:18.988-0500|FINE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=17;_ThreadName=Timer-5;ClassName=com.sun.enterprise.deployment.backend.Deployer;MethodName=finish;_RequestID=39abedd3-860a-408e-8abe-eeca798731ad;|Total
Deployment Time: 4734 msec, Total EJB Compiler Module Time: 32 msec,
Portion spent EJB Compiling: 0%
Breakdown of EJBC Module Time: Total Time for EJBC: 32 msec, CMP
Generation: 0 msec (0%), Java Compilation: 0 msec (0%), RMI Compilation:
0 msec (0%), JAX-RPC Generation: 16 msec (50%),
|#]

[#|2007-10-25T16:46:18.988-0500|FINER|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=17;_ThreadName=Timer-5;ClassName=com.sun.enterprise.deployment.backend.Deployer;MethodName=finish;_RequestID=39abedd3-860a-408e-8abe-eeca798731ad;||#]

[#|2007-10-25T16:46:19.004-0500|SEVERE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=17;_ThreadName=Timer-5;_RequestID=39abedd3-860a-408e-8abe-eeca798731ad;|Exception
occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment
Errorjava.lang.NullPointerException --
Exception Description: Exception was thrown while processing property
[toplink.session.customizer] with value
[brazos.permit.ejb.domain.internal.SequenceCustomizer].
Internal Exception: java.lang.NullPointerException
    at
oracle.toplink.essentials.exceptions.EntityManagerSetupException.failedWhileProcessingProperty(EntityManagerSetupException.java:196)
    at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.processSessionCustomizer(EntityManagerSetupImpl.java:992)
    at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.updateServerSession(EntityManagerSetupImpl.java:968)

-----------------------------------------------
[end log]


Gordon Yorke wrote:
> You will need a SessionCustomizer that allows you to customize the
> Sequences.
>
> _Persistence.xml entry:
> _<property name="toplink.session.customizer"
> value="mypackage.MySequenceCustomizer"/>
>
> _Customizer Class :_
> package mypackage;
> import oracle.toplink.essentials.sessions.Session;
>
> /**
> * PUBLIC:
> * This interface is to allow extra customization on a TopLink Session
> */
> public class MySequenceCustomizer extends SessionCustomizer {
> public void customize(Session session) throws Exception {
>
> session.getDatasourcePlatform().getSequence("OWNER_SEQ").setInitialValue(2);
> }
> }
>
> --Gordon
>
> -----Original Message-----
> *From:* sud [mailto:to_sud_at_yahoo.com]
> *Sent:* Sunday, October 21, 2007 9:18 PM
> *To:* persistence_at_glassfish.dev.java.net
> *Subject:* specifying sequence starting number in DescriptorCustomizer
>
> When using the following workaround for GeneratedValue on a non-id field, is it possible
> to specify the starting number in the sequence?
>
> [Quote]
> As a workaround you can enable this using the TopLink Essentials descriptor
> API. Specify a DescriptorCustomizer in your persistence.xml.
>
> public class MyDescriptorCustomizer implements DescriptorCustomizer {
> public void customize(ClassDescriptor descriptor) {
> descriptor.setSequenceNumberName("OWNER_SEQ");
> descriptor.setSequenceNumberFieldName("number");
> }
> }
> [Quote]
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>