Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Add custom generator re-using table generator(Custom ID generator)
Add custom generator re-using table generator [message #1709921] Thu, 01 October 2015 22:36 Go to next message
Alvaro Sejas is currently offline Alvaro SejasFriend
Messages: 1
Registered: October 2015
Junior Member
I am trying to implement my own TableGenerator strategy (basically the same as default JPA TableGenerator), there is a way to use my own implementation instead of default one? I was trying the approach shown on: https://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing.

I implemented:
public class PrefixCustomSequence extends TableSequence implements SessionCustomizer {
    private String prefix;

    public PrefixCustomSequence(String name, String prefix) {
        super(name);
        this.prefix=prefix;
    }

    @Override
    public Object getGeneratedValue(Accessor accessor,
                                    AbstractSession writeSession, String seqName) {
        Object value=super.getGeneratedValue(accessor,writeSession,seqName)
        return prefix+"_"+value.toString();
    }

....
    public void customize(Session session) throws Exception {
        String idPrefix= (String) session.getProperty("com.property.idPrefix");
        PrefixCustomSequence sequence = new PrefixCustomSequence("prefix-custom",idPrefix);
        session.getLogin().addSequence(sequence);
    }
}

I am extending TableSequence in order to re-use all bundled functionality. But there is no way to force EclipseLink to use this implementation instead of default TableSequence.

Is there a way to do this in EclipseLink JPA? or is better to use UUIDs?
Re: Add custom generator re-using table generator [message #1709993 is a reply to message #1709921] Fri, 02 October 2015 14:13 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
In the example in the link you provided, it shows you would use the sequence generator you've defined by specifying the entity to use the generator named"prefix-custom".

Otherwise, if you want your defined sequence to override the default used by EclipseLink in the session's login, use setDefaultSequence instead of addSequence on session.getLogin().

Best Regards,
Chris
Previous Topic:EclipseLink issue in WLS 12c JPQL query compilation issue: can't be resolved to a valid type
Next Topic:Cache coordination propagation mode with JGroups
Goto Forum:
  


Current Time: Thu Apr 18 05:48:27 GMT 2024

Powered by FUDForum. Page generated in 0.01848 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top