Customization default sequence name. [message #516846] |
Thu, 25 February 2010 06:06  |
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 #518024 is a reply to message #516846] |
Tue, 02 March 2010 14:35   |
James Sutherland Messages: 1834 Registered: July 2009 |
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
|
|
|
| Re: Customization default sequence name. [message #518237 is a reply to message #518024] |
Wed, 03 March 2010 10:14  |
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.
|
|
|
Powered by
FUDForum. Page generated in 0.01989 seconds