-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using @GeneratedValue for getting non-key unique properties
PostPosted: Thu Dec 07, 2006 9:57 pm 
Newbie

Joined: Mon Aug 28, 2006 6:31 am
Posts: 16
Hello,

is there any way to use a @GeneratedValue (@GenericGenerator, UserType...) for automated getting of uniqie values for non-key properties.

I need to generate the customer id's with a spezial name conventions: e.g. B0123456.

I think, it doesn't make sense to use those bussines identifier as a primary keys. But i didn't find any simple possibility to generate such unique/incremented values for non-primary key fields yet.

The @Embeddable with one @Id-annotated collumn could be a workaround, but it doesn't support any type of @GeneratedValue. (and if, how would i get 'B' before @Id?).

So i need a help!

Many thanks, Gena


Top
 Profile  
 
 Post subject: Resume
PostPosted: Wed Feb 21, 2007 8:42 am 
Newbie

Joined: Mon Aug 28, 2006 6:31 am
Posts: 16
Hi, its a pity that nobody had an idea.

It's possible, that my post is to stupid to be answered. But in my opinion, there are many cases in which a DB-wide unique identifier could be usefull or needed. Its also possible to retrieve it from the underlying db using hibernate before the entity is persisted, but if those retrieved value will be used as surrogate pk we need an approach to say the hibernate, that the entity is transient and must be inserted and not updated (so we need no select before, since its clear to us, the entity is transient).

The second possibility is to create a dummy entity with a desired id generation strategy and get the unique id for it but not persist this heler entity at all (its a dummy). We get the same problem as in a paragraph above, because the id will be retrieved only at the insertion time. We need to use a hibernate metadata of a desired (dummy) entity with a desired id-generation strategy to get an unique identifier by using hibernate.

If some one is intrested on this approach/idea, please read following article i found usefull:
http://www.devx.com/Java/Article/30396/1954?pf=true


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

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.