[ebean] NamingConvention enhancement

129 views
Skip to first unread message

Daryl Stultz

unread,
May 19, 2010, 4:11:15 PM5/19/10
to Ebean ORM
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<String, String> seqMap = new HashMap<String, String>();
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 Bygrave

unread,
May 19, 2010, 9:26:41 PM5/19/10
to eb...@googlegroups.com
Yes, I think this is a good enhancement.

Logged as http://www.avaje.org/bugdetail-296.html

Rob Bygrave

unread,
May 20, 2010, 7:45:24 AM5/20/10
to eb...@googlegroups.com
I've made a small change in NamingConvention to support this enhancement. 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 (assuming you are using one of the built in naming conventions).


This change is now in HEAD.


Cheers, Rob.

Daryl Stultz

unread,
May 20, 2010, 8:33:50 AM5/20/10
to Ebean ORM


On May 20, 7:45 am, Rob Bygrave <robin.bygr...@gmail.com> wrote:
> I've made a small change in NamingConvention to support this enhancement.
> Specifically the pkColumn parameter was added to the getSequenceName()
> method.

I rebuilt from HEAD to try this and I get this error:

java.lang.NoClassDefFoundError: org/apache/lucene/analysis/Analyzer
at
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
193)
at
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
124)
at
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
63)
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:
64)
at com.avaje.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:237)

Is Lucene a dependency now? I downloaded Lucene 2.9.2 but then I get
this:

java.lang.NoSuchFieldError: LUCENE_30
at
com.avaje.ebeaninternal.server.core.InternalConfiguration.createLuceneManager(InternalConfiguration.java:
189)
at
com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:
151)
at
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
193)

Doe Lucene really need to be a dependency?

/D

Rob Bygrave

unread,
May 20, 2010, 4:52:51 PM5/20/10
to eb...@googlegroups.com
> Doe Lucene really need to be a dependency?

It should be a compile only dependency ... but right now that obviously is not the case looking at this stack trace.

That is Lucene 3.0.1 (it looks to be in the pom)

... I'll fix this up so that it is only needed for compile. Sorry.

Daryl Stultz

unread,
May 20, 2010, 9:03:04 PM5/20/10
to Ebean ORM


On May 20, 7:45 am, Rob Bygrave <robin.bygr...@gmail.com> wrote:
> I've made a small change in NamingConvention to support this enhancement.
> Specifically the pkColumn parameter was added to the getSequenceName()
> method.
>
> public String getSequenceName(String tableName, String pkColumn);

I've confirmed this works for my needs

>
> NOTE: if you put into ebean.properties something like:
>
> ebean.h2.namingConvention.sequenceFormat={table}_{column}_seq
>

I can't seem to get this to work:

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

Not sure what you mean by "using one of the built in naming
conventions".

Oh wait, this works:

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

(with ebean.namingConvention commented out.

/Daryl

Rob Bygrave

unread,
May 21, 2010, 8:01:02 PM5/21/10
to eb...@googlegroups.com
> I can't seem to get this to work:
> ebean.namingConvention=com.avaje.ebean.config.MatchingNamingConvention
> ebean.h2.namingConvention.sequenceFormat={table}_{column}_seq
 
Thanks Daryl...  yes, that was a scenario I didn't take into account.

So fixed that and now if a namingConvention is created via ebean.properties (that extends Ebean's AbstractNamingConvention) then the sequenceFormat can also be loaded from ebean.properties and used.


Ta, Rob.
Reply all
Reply to author
Forward
0 new messages