-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: "Slug" generation using Event Listeners
PostPosted: Thu Sep 20, 2012 11:33 am 
Newbie

Joined: Mon Feb 02, 2009 8:56 am
Posts: 6
Hi,

There are few places in my application where I need to generate "slugs" or friendly identifiers for my entities. For example, a product named "Hibernate in Action" should get its slug generated as "hibernate-in-action". Of course, if an entity with the same slug already exists in the database, a number is appended to avoid conflicts (e.g. "hibernate-in-action1").

I've been generating all this names in each of my application services, which leads to duplicate code. So I was wondering if I could get this done in a single point, such as a PreInsert Event Listener, but got some trouble as I would need to perform some queries (to find possible duplicates) inside onPreInsert, which (I think) flushes the session and causes failure, so maybe it's not the best place to do this kind of things.

Can anybody give me some advice on how to do this? Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.