Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Customization default sequence name.
icon5.gif  Customization default sequence name. [message #516846] Thu, 25 February 2010 06:06 Go to next message
Radek Hodain is currently offline Radek Hodain
Messages: 16
Registered: February 2010
Junior Member
Hi all.

I would like to ask you, how to customize default sequence name.
We use Oracle database. In entity mapping we use something like this:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "entity_id")
private Integer id;

My first task is to set up the SequenceGenerator as a default generator, because OraclePlatform chooses the TableGanerator as default for GenerationType.AUTO.
I did it via SessionCustomizer

public void customize(Session session) throws Exception {
session.getLogin().setDefaultSequence(new NativeSequence());
}

Now, when I use Generation.AUTO eclipse link uses SequenceGenerator and produces SQL like this:

SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL.

My second task is to modify SQL. We use sequence name based on table name. So, our sequence name are SEQ_USER or SEQ_GROUP etc. Default sequence generator uses the static sequence name. I will get the same sequence name from all entities. Does anybody know how to build sequence name dynamically with table name of entity. I have tried to build own SequenceGenerator but I am not able to get table name there.

PS: We have solved it in hibernate and openjpa whose generate sequence name dynamically but I am not able to find this feature in eclipselink. If I don't use annotation SequenceGenerator or TableGenerator with definition I get every time the same static sequence name or table name.

Thanks a lot for your advice.


[Updated on: Fri, 26 February 2010 04:25]

Report message to a moderator

Re: Customization default sequence name. [message #516996 is a reply to message #516846] Thu, 25 February 2010 12:11 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1016
Registered: July 2009
Senior Member
Hello,

If the generator isn't specified within the @GeneratedValue, the provider uses a default. You probably want to use the SEQUENCE type instead of AUTO, and specify the sequence object name within the @SequenceGenerator.

@GeneratedValue and @SequenceGenerator are apart of the JPA specification,and so should not require any changes when switching JPA providers.

An example of a SequenceGenerator shown at:
http://wiki.eclipse.org/Introduction_to_EclipseLink_JPA_(ELUG)#.40SequenceGenerator
Only difference from the example provided is that you will need to specify the sequenceName within SequenceGenerator.

Best Regards,
Chris


Re: Customization default sequence name. [message #517033 is a reply to message #516996] Thu, 25 February 2010 14:56 Go to previous messageGo to next message
Radek Hodain is currently offline Radek Hodain
Messages: 16
Registered: February 2010
Junior Member
Thank you for your answer.

I might not have explained it enough. I know I can use what have you written. I try to find solution which alowed me to generate correct sequence name without changing entity mapping, because I have really huge domain model. I don't want to write new annotations into each of entities. In hibernate and openjpa is possible to define or modify existing sequence generator and make him generate correct sequence name based on table name dynamically.
Now I know in eclipselink I can use @SequenceGenerator and define sequence name. If I don't use @SequenceGenerator eclipselink generates default sequence name SEQ_GEN. I need to generate sequence name dynamically in java code without chaging the mapping.
Re: Customization default sequence name. [message #518024 is a reply to message #516846] Tue, 02 March 2010 14:35 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can use a SessionCustomizer to define this in code,

for each descriptor that is using sequencing you can set its sequenceName (ClassDescriptor.setSequenceName()), or use the one that was generated, this refer to a Sequence object in the Session's DatabaseLogin, you can then create a new NativeSequence for each descriptor with the name based on the descriptor's table name and add it to the Session's DatabaseLogin.



James : Wiki : Book : Blog : Twitter
Re: Customization default sequence name. [message #518237 is a reply to message #518024] Wed, 03 March 2010 10:14 Go to previous message
Radek Hodain is currently offline Radek Hodain
Messages: 16
Registered: February 2010
Junior Member
Thank you very much James.

It is absolutely what we need. So I am a little bit confused with methods session.getDescriptors and session.getDescriptorForAlias(String). Each of them returns as a result different Map. GetDescriptors return value of attribute orderedDescriptors and getDescriptorsForAlias value from attribute aliasesDescritors from an instance of Project.class. I have to use method getDescriptorsForAliases(Sring) to obtain correct instace of classDescriptor and I to set sequenceNumberName correctly. If I obtain classDescriptor by method getDescriptors it did'nt work.
Previous Topic:Problem with Cascade.REMOVE with OneToMany relationship JSE [FIXED]
Next Topic:IndexOutOfBoundsException in ObjectBuilder
Goto Forum:
  


Current Time: Thu Jul 24 06:43:22 EDT 2014

Powered by FUDForum. Page generated in 0.01910 seconds