[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| 
Re: [eclipselink-users] How to use QuerySequence of eclipselink
 | 
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.
shivsingh.06nov wrote:
> 
> 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>
>> 
>> 
>> 
> 
> 
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/How-to-use-QuerySequence-of-eclipselink-tp24931901p25046445.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.