How to use QuerySequence of eclipselink

View: New views
4 Messages — Rating Filter:   Alert me  

How to use QuerySequence of eclipselink

by Manupriya :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am trying to use QuerySequence class to create customized generator using database sequence.
We I am trying to add it in persistence.xml I am getting ClassNotFoundExcetion.
Can anyone tell me how to use QuerySequence?

Regards,

Re: How to use QuerySequence of eclipselink

by Andrei Ilitchev :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

QuerySequence is a base class for TableSequence and NativeSequence - classes
used to support JPA TableGenarator and SequenceGenerator/Identity.

To define customized database sequence I would first look at overriding
NativeSequence (not QuerySequence).

To assign custom sequence to entity I would use SequenceGenerator.

@Entity
public class Address {
    ...
    @GeneratedValue(generator="ADDRESS_SEQ")

    @SequenceGenerator(name="ADDRESS_SEQ", allocationSize=25)

    @Column(name="ADDRESS_ID")

    public int getId() {

        return id;

    }
...
}


Then in SessionCustomizer substitute the original sequence for the customary
one:

public class MyCustomizer implements SessionCustomizer {

public void customize(Session session) {

    Sequence originalSequence =
session.getPlatform().getSequence("ADDRESS_SEQ");

    session.getPlatform().addSequence(MySequence("ADDRESS_SEQ",
originalSequence.getPreallocationSize()));

}


MyCustomizer class should be packed with the rest of the persistence unit
(into the same jar with entity classes)
and should be listed in the properties in persistence.xml (or properies
passed to createEntityManagerFactory):
        <properties>
            ...
            <property name="eclipselink.session.customizer"
value="MyCustomizer"/>
        </properties>





----- Original Message -----
From: "Manupriya" <manupriya.sinha@...>
To: <eclipselink-users@...>
Sent: Wednesday, August 12, 2009 5:50 AM
Subject: [eclipselink-users] How to use QuerySequence of eclipselink


>
> Hi,
>
> I am trying to use QuerySequence class to create customized generator
> using
> database sequence.
> We I am trying to add it in persistence.xml I am getting
> ClassNotFoundExcetion.
> Can anyone tell me how to use QuerySequence?
>
> Regards,
> --
> View this message in context:
> http://www.nabble.com/How-to-use-QuerySequence-of-eclipselink-tp24931901p24931901.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: How to use QuerySequence of eclipselink

by shivsingh.06nov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andrei,

Thanks for your reply. I want to use stored procedure to generate id for me. I want to pass sequence name to it and stored procedure would use it for generating the sequence id.
Is it possible to create custom ID generator that can call stored procedure for generating value for id field?

Regards,
Shivendra
Andrei Ilitchev wrote:
QuerySequence is a base class for TableSequence and NativeSequence - classes
used to support JPA TableGenarator and SequenceGenerator/Identity.

To define customized database sequence I would first look at overriding
NativeSequence (not QuerySequence).

To assign custom sequence to entity I would use SequenceGenerator.

@Entity
public class Address {
    ...
    @GeneratedValue(generator="ADDRESS_SEQ")

    @SequenceGenerator(name="ADDRESS_SEQ", allocationSize=25)

    @Column(name="ADDRESS_ID")

    public int getId() {

        return id;

    }
...
}


Then in SessionCustomizer substitute the original sequence for the customary
one:

public class MyCustomizer implements SessionCustomizer {

public void customize(Session session) {

    Sequence originalSequence =
session.getPlatform().getSequence("ADDRESS_SEQ");

    session.getPlatform().addSequence(MySequence("ADDRESS_SEQ",
originalSequence.getPreallocationSize()));

}


MyCustomizer class should be packed with the rest of the persistence unit
(into the same jar with entity classes)
and should be listed in the properties in persistence.xml (or properies
passed to createEntityManagerFactory):
        <properties>
            ...
            <property name="eclipselink.session.customizer"
value="MyCustomizer"/>
        </properties>





----- Original Message -----
From: "Manupriya" <manupriya.sinha@gmail.com>
To: <eclipselink-users@eclipse.org>
Sent: Wednesday, August 12, 2009 5:50 AM
Subject: [eclipselink-users] How to use QuerySequence of eclipselink


>
> Hi,
>
> I am trying to use QuerySequence class to create customized generator
> using
> database sequence.
> We I am trying to add it in persistence.xml I am getting
> ClassNotFoundExcetion.
> Can anyone tell me how to use QuerySequence?
>
> Regards,
> --
> View this message in context:
> http://www.nabble.com/How-to-use-QuerySequence-of-eclipselink-tp24931901p24931901.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: How to use QuerySequence of eclipselink

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This should be possible.  In your SessionCustomizer just set the sequence to an instance of QuerySeqeunce and set the selectQuery (setSelectQuery) to an instance of ValueReadQuery that uses a StoredProcedureCall.


Hi Andrei,

Thanks for your reply. I want to use stored procedure to generate id for me. I want to pass sequence name to it and stored procedure would use it for generating the sequence id.
Is it possible to create custom ID generator that can call stored procedure for generating value for id field?

Regards,
Shivendra
Andrei Ilitchev wrote:
QuerySequence is a base class for TableSequence and NativeSequence - classes
used to support JPA TableGenarator and SequenceGenerator/Identity.

To define customized database sequence I would first look at overriding
NativeSequence (not QuerySequence).

To assign custom sequence to entity I would use SequenceGenerator.

@Entity
public class Address {
    ...
    @GeneratedValue(generator="ADDRESS_SEQ")

    @SequenceGenerator(name="ADDRESS_SEQ", allocationSize=25)

    @Column(name="ADDRESS_ID")

    public int getId() {

        return id;

    }
...
}


Then in SessionCustomizer substitute the original sequence for the customary
one:

public class MyCustomizer implements SessionCustomizer {

public void customize(Session session) {

    Sequence originalSequence =
session.getPlatform().getSequence("ADDRESS_SEQ");

    session.getPlatform().addSequence(MySequence("ADDRESS_SEQ",
originalSequence.getPreallocationSize()));

}


MyCustomizer class should be packed with the rest of the persistence unit
(into the same jar with entity classes)
and should be listed in the properties in persistence.xml (or properies
passed to createEntityManagerFactory):
        <properties>
            ...
            <property name="eclipselink.session.customizer"
value="MyCustomizer"/>
        </properties>