I don't understand how to use the generated java code from the hibernate tools. I have 3 tables, USERS, HOSTS, and HOSTS_IN_USE. The USERS table has a primary key ID column, varchar NAME, etc. Same with the HOSTS table. The HOSTS_IN_USE table has 2 columns, USER_ID and HOST_ID; when a host is in use the IDs for it and the user using it are added to the HOSTS_IN_USE table. Here's the ddl for the HOSTS_IN_USE table using postgres:
Code:
CREATE TABLE waitlist2.hosts_inuse (
host_id integer NOT NULL,
user_id integer NOT NULL,
"time" timestamp without time zone NOT NULL,
CONSTRAINT hosts_inuse_host_id_fk FOREIGN KEY (host_id)
REFERENCES waitlist2.hosts (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT hosts_inuse_user_id_fk FOREIGN KEY (user_id)
REFERENCES waitlist2.users (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
The generated java for the Host class (from the HOSTS table) has in it
Code:
private Set<HostsInuse> hostsInuses = new HashSet<HostsInuse>(0);
with the usual getters and setters.
And then I have these other classes which I don't understand how I should use them:
Code:
/**
* HostsInuse generated by hbm2java
*/
@Entity
@Table(name="hosts_inuse"
,schema="waitlist2"
)
public class HostsInuse implements java.io.Serializable {
private HostsInuseId id;
private Host host;
private User user;
Code:
/**
* HostsInuseId generated by hbm2java
*/
@Embeddable
public class HostsInuseId implements java.io.Serializable {
private int hostId;
private int userId;
private Date time;
When I retrieve a host that's in the HOSTS_IN_USE table, its hostsInuses field (the one of type of Set<HostsInuse>) has an entry in it; if it's not in the HOSTS_IN_USE table the Set is empty.
What I'm confused about is how to write my code that checks to see if a Host is in use; should I just use host.hostsInuses.isEmpty() ?
I'm starting to feel that I need to write a class that presents a nicer interface than this Host class generated by the hibernate tools and convert each Host before I use it, in my dao. That seems klunky though.