Skip to main content



      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 18:36 Go to next message
Eclipse UserFriend
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 10:13 Go to previous message
Eclipse UserFriend
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: Mon Jul 14 05:17:05 EDT 2025

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

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

Back to the top