adding a character to primary key in JPA using EclipseLink -


i want add character primary b1,b2,b3 , on.

i using sequence generate number part of primary key , in entiy class setter method, adding b number generated. primary key comumn in database created number [sequence value only], b not appended @ all, when debugged found setter method not called when creating value.

i using eclipselink2.4, jpa 2 in weblogic 12c.

would appeciate suggestions , solutions.

 @id     @basic(optional = false)     @column(name = "bundle_msg_id")     @sequencegenerator(name="db_seq", sequencename="db_seq", allocationsize=1)     @generatedvalue(strategy= generationtype.sequence, generator="db_seq")     private string bundlemsgid;      public string getbundlemsgid() {               return this.bundlemsgid;     }      public void setbundlemsgid(string bundlemsgid) {               if( bundlemsgid != null && !bundlemsgid.startswith("b")){                   this.bundlemsgid = "b"+bundlemsgid;       }            this.bundlemsgid = bundlemsgid;     } 

using set method not work, database assigns sequence value, not jpa provider. provider getting value database, not other way around.

the best way accomplish might setup trigger in database assign sequence, , jpa sequence can read in value using identity generationtype instead. may need indicate identity supported on platform described in post http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg01320.html

an alternative create own custom sequencing class, described here http://wiki.eclipse.org/eclipselink/examples/jpa/customsequencing . use org.eclipse.persistence.sequencing.nativesequence class model, , prepend character needed.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -