I'm using Hibernate Annotations 3.3.0 and Hibernate Core 3.2.3. I have two very simple tables; a users table and a user_roles table. Each user has one or more user_roles as follows:
Code:
create table users (
id varchar(6) not null primary key,
last_active_date date,
.... etc. ...
);
create table user_roles (
user_id varchar(6),
role varchar(10)
);
user_roles.user_id is a foreign key to the users table.
I have a User class which maps to the users table and I would like to have a Java property "String[] roles" instead of "UserRoles[] roles" where I define a Java class for the user_roles table when I only need one field out of it. Abbreviated example:
Code:
@Entity
@Table(name = "users")
// Something goes here?
public class User {
private String id;
private Date lastActive;
private String[] roles;
@Id
@Column(length = 6)
public String getId() {
return id;
}
@Column(name = "last_active", nullable = false)
public Date getLastActive() {
return lastActive;
}
// what goes here??
public String[] getRoles() {
return roles;
}
}
Can this be done? I know it's nit-picky, I just hate the idea of creating a separate class when I only need one field out of this table. Plus, my brain counts the bytes of memory an additional two objects for each user role will consume (I can't seem to let go of my "4KB of RAM" days).
Thanks,
Daniel