-->
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.  [ 7 posts ] 
Author Message
 Post subject: Basic design question with domain model
PostPosted: Wed Aug 18, 2004 7:11 am 
Newbie

Joined: Wed Aug 18, 2004 6:51 am
Posts: 12
Location: Tampere, Finland
I am just starting to research into the world of Hibernate, so newbie warning for the following question. I do not have much knowledge yet, and will probably get answers to my questions sooner or later from some material that I study, but would like some feedback already at this phase.

As I understand, my objects need to be JavaBeans for Hibernate to be able to map them - right? Now, I could almost instantly think of a case where this is a problem. Let's say I have a User object. User has a password, which is stored hashed in database. My "pure" object would be like:

class User {
private hashedPassword;
public void setPassword(String pw) {
hashedPassword = hash(pw);
}

public String getHashedPassword() {
return hashedPassword;
}
}

I do not want to expose anything extra - no getter for unhashed password, no setter for hashed password. What I really want hibernate to do is to persist the object's private attributes. What would be a good way to accomplish this? This is just a simple example, but I think majority of cases will have some properties that should not be exposed through getters and setters. So should I a) mess up my business object's interface or b) use Hibernate to persist something else than my business object?

For b), one solution would be to have the internal state in a DTO and use hibernate to persist those objects. As in

class User {
UserDTO dto;

public String getHashedPassword() {
return dto.getHashedPassword();
}
}

class UserDAO {
public void store(UserDTO dto) {
//...do some Hibernate magick
}
}

This feels quite inflexible, though, and I am not sure how well it suits Hibernate's features such as automatically persisting / fetching object graphs etc.

Any wise advice?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 7:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just use access=field and map a property with name="hashedPassword"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 7:22 am 
Newbie

Joined: Wed Aug 18, 2004 6:51 am
Posts: 12
Location: Tampere, Finland
Wouldn't this throw a Security(or some other)Exception as the field is private?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 7:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No. Probably yes if you have a restrictive SecurityManager in effect. Just try it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 7:25 am 
Newbie

Joined: Wed Aug 18, 2004 6:51 am
Posts: 12
Location: Tampere, Finland
I will.

So my assumption "objects have to be JavaBeans to be persisted" was wrong....wonder where I picked that up. Thanks for clearing that up!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 9:40 pm 
Newbie

Joined: Wed Jun 23, 2004 8:51 pm
Posts: 16
michael wrote:
No. Probably yes if you have a restrictive SecurityManager in effect. Just try it.

How does this actually work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 9:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Accessing members of a class through the introspection API is allowed even though the members are defined with a visibility the caller would not be able to "see" without using introspection. This is true unless a security manager is set which explicitly disallows this; but the default security manager does allow it.


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