Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

create generator hibernate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class PublisherCodePrefixedSequenceIdGenerator extends SequenceStyleGenerator {
     
    public static final String CODE_NUMBER_SEPARATOR_PARAMETER = "codeNumberSeparator";
    public static final String CODE_NUMBER_SEPARATOR_DEFAULT = "_";
     
    public static final String NUMBER_FORMAT_PARAMETER = "numberFormat";
    public static final String NUMBER_FORMAT_DEFAULT = "%05d";
     
    private String format;
     
    @Override
    public Serializable generate(SharedSessionContractImplementor session,
            Object object) throws HibernateException {
        return String.format(format, ((Book)object).getPublisher().getCode(), super.generate(session, object));
    }
     
    @Override
    public void configure(Type type, Properties params,
            ServiceRegistry serviceRegistry) throws MappingException {
        super.configure(LongType.INSTANCE, params, serviceRegistry);
        String codeNumberSeparator = ConfigurationHelper.getString(CODE_NUMBER_SEPARATOR_PARAMETER, params, CODE_NUMBER_SEPARATOR_DEFAULT);
        String numberFormat = ConfigurationHelper.getString(NUMBER_FORMAT_PARAMETER, params, NUMBER_FORMAT_DEFAULT).replace("%", "%2"); 
        this.format = "%1$s"+codeNumberSeparator+numberFormat; 
    } 
}
Comment

PREVIOUS NEXT
Code Example
Java :: java producer consumer queue 
Java :: factorial function in java recursion 
Java :: raspberry stackexchange how to install the java jdk 
Java :: max head java 
Java :: set class return type by jenric in java 
Java :: on offline event spigot example 
Java :: imagebutton get background color programmatically 
Java :: does not have a NavController set on 21312310 kotlin 
Java :: Static And Public Methods 
Java :: x^n+y^n=z^n 
Java :: get top 3 entries based on values map java 
Java :: java union of sets 
Java :: Join Two Java Strings 
Java :: minecraft block java 
Java :: buffered reader for big integer 
Java :: produces 
Java :: programically set data source properties in spring 
Java :: get bimap by uri in android 
Java :: how to open a folder in java swing project 
Java :: what does % do in java 
Java :: model mapper with Page 
Java :: fill a 2d array java 
Java :: find namestart with name using strim in java 
Java :: get value from dynamic input android 
Java :: Description Resource Path Location Type ApplicationContext cannot be resolved to a type Mobile.java /InversionOfControl/src/com/deloitte/springioc line 13 Java Problem 
Java :: String length equality 
Java :: thread Exemple 
Java :: How to handle exceptions thrown by application with another servlet? 
Java :: Double matrix 
Java :: viewResolver 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =