[jboss-user] [EJB 3.0] - Re: JBoss and PostgreSQL 8.1

fermat42 do-not-reply at jboss.com
Thu Aug 2 04:55:33 EDT 2007


For sure I can. Sorry I copied only one of the ID Fields:

Server.java:

package de.douglas2a.components;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToMany;

@Entity
@IdClass(ComponentPK.class)
public class Server implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Id
    private Long sessionId;
    
    private String hostname;
    
    private String ip;
    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getSessionId() {
        return sessionId;
    }
    
    public String getHostname() {
        return hostname;
    }
    
    public void setHostname(String hostname) {
        this.hostname = hostname;
    }
    
    public String getIp() {
        return ip;
    }
    
    public void setIp(String ip) {
        this.ip = ip;
    }

    public Server() {
    }
    
    public Server(Long sessionId) {
        this.sessionId = sessionId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
    
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Server)) {
            return false;
        }
        Server other = (Server)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }
    
    @Override
    public String toString() {
        return "de.upb.vdrive.components.Server[id=" + id + "]";
    }
}


ComponentPK.java:

package de.douglas2a.components;

public class ComponentPK implements java.io.Serializable {
    
    private Long id;
    
    private Long sessionId;
    
    public ComponentPK() {
    }
    
    public ComponentPK(Long id, Long sessionId) {
        this.id = id;
        this.sessionId = sessionId;
    }
    
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof ComponentPK)) return false;
        ComponentPK pk = (ComponentPK)obj;
        if (!id.equals(pk.id)) return false;
        if (!sessionId.equals(pk.sessionId)) return false;
        return true;
    }
    
    public int hashCode( ) {
        int id = this.id.intValue();
        int sid = this.sessionId.intValue();
        return id + Integer.reverse(sid);
    }
}


If needed I can also post my config-files for configuring Postgre as Datasource...

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4069990#4069990

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4069990



More information about the jboss-user mailing list