-->
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.  [ 6 posts ] 
Author Message
 Post subject: Encapsulating Keys
PostPosted: Fri Jan 16, 2004 6:10 am 
Newbie

Joined: Sat Jan 10, 2004 5:45 pm
Posts: 12
Location: Hong Kong
Hello.

To maximize the encapsulation, I'd like to model Cat like this:

public abstract class Cat {
protected Key getPrimaryKey();
protected void setPrimaryKey(Key k);
}

public abstract class Key {
public abstract String toString();
}

The objective of this design is to allow independence on using the internal representation of key e.g. change from long integer to UUID.

The problem goes on mapping: as the id is now an object, how to define the mapping file without using the composite-id method (as it is highly undesirable)?

Thx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 6:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a custom user type propably. IMHO it would be better anyways to simply keep your key a String and use a UserType to map from the underlying database types. Note that with such IMHO ugly constructs, you will probably not be able to use some generators like increment, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 6:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I am even not sure if you can use any generators besides assigned.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 3:26 pm 
Newbie

Joined: Sat Jan 10, 2004 5:45 pm
Posts: 12
Location: Hong Kong
gloeglm wrote:
Use a custom user type propably. IMHO it would be better anyways to simply keep your key a String and use a UserType to map from the underlying database types. Note that with such IMHO ugly constructs, you will probably not be able to use some generators like increment, etc.


I'd like to know more on the disadvantages besides the coding effort.
As design is always a trade-off activities, I'd like to know more about the disadvantage on using this design from an object-oriented, object-relational mapping, and db schema design persepectives.

Let me list out what I believe I can gain:
1. Key internal type independence: now every object can be identified by instances of Key object, without exposing the actual type of the key.
2. PlaceHolder for the capturing Key's behaviour and operations: as we have defined a class Key we can further define its behaviours and some operations within the class
...

And The costs:
1. More code: making custom type.
...

Thx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 3:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The costs:
1. More code
2. Additional model complexity
3. Creating Functionality you will most likely never need

What I would suggest: Stick to the YAGNI Principle and leave it out.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 6:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, you can write your own id generator and use that.


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