-->
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.  [ 3 posts ] 
Author Message
 Post subject: @BusinessKey in Validator - no more equals and hashcode
PostPosted: Thu Apr 03, 2008 11:18 am 
Newbie

Joined: Fri Feb 08, 2008 11:10 am
Posts: 3
Hi,

Would it be a good or bad idea to create a org.hibernate.validator.annotation.BusinessKey annotation?

The goal is create a mean to use Entities in hash-based classes no matter the Entity is transient, detached or persistent.

So the use case: I have an "normal" entity with @Id, @OneToMany aso.

I add..

@BusinessKey
String email;

...to the email and possibly to several other fields. And then:

1) A unique constraint will be added in the DDL for those properties forming the business key

2) @PrePersist and @PreUpdate will verify the the business key is set

3) If build-time bytecode instrumentation has been used, the equals and hashcode methods will be enhanced to use the business key in the comparison.

Then, hopefully, I'd be able to use my entities in any hash-based collection regardless of the state? Or is there a more clever way to achieve this declaratively?

br,
Jens


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 6:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
that sounds nice, though I don't like part 3.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 3:54 pm 
Newbie

Joined: Mon Nov 26, 2007 12:49 pm
Posts: 7
Hi jensaug,

It's funny that you're mentioning this @BusinessKey annotation, I've just implemented something like this yesterday. It allows you to declare a business key for an object using a @BusinessObject annotation.
Then you can declare in the annotation if the business key inherits from the parent class (or interfaces) in the case you have inheritance.

It works like a charm except for entities having all fields nullable (except the ID). In that case I've no other way than using a business key containing the ID of the entity.

This annotation can then be used with an AnnotatedBusinessObject class that read the business key from the @BusinessObject annotation and then redefine the hashCode() and equals() methods to use that business key.

If you're interested I can compile a tar file containing the source (I don't have an open source project for this).


Cheers,
/Benoit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.