Add custom generator re-using table generator [message #1709921] |
Thu, 01 October 2015 18:36  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04559 seconds