Customization default sequence name. [message #516846] |
Thu, 25 February 2010 11: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 09:25] Report message to a moderator
|
|
|
|
|
Re: Customization default sequence name. [message #518024 is a reply to message #516846] |
Tue, 02 March 2010 19:35 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02814 seconds