Enhancement 296 : ENHANCEMENT - NamingConvention to support Sequences with primary key column
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.7.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
20/05/2010
Updated 
20/05/2010
Type 
Enhancement
 
Attachments 
No attachments

I use PostgreSQL. Sequences (when generated by specifying SERIAL as
the datatype) follow this pattern:

schema.tablename_columnname_seq

I have a NamingConvention to get sequence values. I have a map like
so:

HashMap seqMap = new HashMap();
seqMap.put("public.roles", "roles_roleid_seq");
seqMap.put("public.userroles", "userroles_userroleid_seq");
seqMap.put("public.users", "users_userid_seq");
seqMap.put("public.usertypes", "usertypes_usertypeid_seq");

I can generate this from the database, but I'd prefer to do this by
convention for easier maintenance. I'm wondering if we could have a
getSequenceNameByConvention method. I suppose this would take the
class. I'd fish out the table name and id column name to form the
sequence name.

Thanks.

/Daryl

 
Rob 20 May 11:44
Fixed in HEAD.

This required a small change to the API for NamingConvention.

Specifically the pkColumn parameter was added to the getSequenceName() method.

public String getSequenceName(String tableName, String pkColumn);


NOTE: if you put into ebean.properties something like:

ebean.h2.namingConvention.sequenceFormat={table}_{column}_seq

Then the "{table}_{column}_seq" format is used to define the sequence names.

Rob 21 May 02:08
Note ... also...

This fix didn't take into account creating a NamingConvention that is created by ServerConfig when defined in ebean.properties

i.e. this didn't work

ebean.namingConvention=com.avaje.ebean.config.MatchingNamingConvention
ebean.h2.namingConvention.sequenceFormat={table}_{column}_seq


Fixed that scenario now.

woResponse

Upload a file