miércoles, 13 de junio de 2007

Ejemplo heritance jpa

package es.miao;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "color_primaria")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="tipo", discriminatorType=DiscriminatorType.STRING, length=3)
@DiscriminatorValue(value="PRI")
public class CombinacionColorPrimaria implements Serializable {

//seam-gen attributes (you should probably edit these)
private Long id;
private Integer version;
private Color color;

//add additional entity attributes

//seam-gen attribute getters/setters with annotations (you probably should edit)

@Id @GeneratedValue
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Version
public Integer getVersion() {
return version;
}

private void setVersion(Integer version) {
this.version = version;
}

@ManyToOne
public Color getColor() {
return color;
}

public void setColor(Color color) {
this.color = color;
}


}


package es.miao;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.validator.Length;

@Entity
@DiscriminatorValue(value="SEC")
public class CombinacionColorSecundaria extends CombinacionColorPrimaria implements Serializable {






}

No hay comentarios: