@Basic not working

Hi,

I've the class below. What i would like to do is that whenever i find a record by using named query, i wouldn't want the password field to be retrieved, because i don't want to pass it through the network to the client.

Therefore, i've found this @Basic annotation which supposedly can do lazy fetching for the password field according to the reference that i found. But after i tried, it's not working. Whenever i call user.getPassword(), i still able to get the value.

Then, i come across this page:

http://java.sun.com/developer/technicalArticles/ebeans/ejb_30/

it states:

Keep in mind that a FetchType of EAGER is a requirement on the persistence provider, whereas a fetchType of LAZY is only a hint. So even though you may specify the fetchType to be LAZY, the persistence provider may choose to load the attribute eagerly.

But i would really want to achieve what i wanted to do, which is not retrieving the password value when i do a normal find record.

Are there any setting for this @Basic annotation so that the persistence provider will lazy fetch it? Or are there any other way to achieve my objective?

@NamedQueries({

@NamedQuery(name ="User.authenticateUser", query ="select u from User u "

+"where u.userId=:userId and u.password=:password "),

@NamedQuery(name ="User.findUserByUserId", query ="select u from User u "

+"where u.userId=:userId")})

@Entity

@Table(name ="SY01USR")

publicclass User{

private String userId;

private String password;

publicvoid setUserId(String userId){

this.userId = userId;

}

@Id

@Column(name ="USR_ID")

public String getUserId(){

return userId;

}

publicvoid setPassword(String password){

this.password = password;

}

@Column(name ="PSWD")

@Basic(fetch=FetchType.LAZY)

public String getPassword(){

return password;

}

}

[2946 byte] By [keisuke.takahashia] at [2007-11-27 3:41:23]
# 1

if you call user.getPassword() you are loading the password.

Lazy loading means, dont load the property until the property method is called.

if you call getPassword() method, the password gets loads if it is not loaded perviously.

try using toString() for the component after fetching it.

hope this will help.

amarpolimeraa at 2007-7-12 8:44:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...