[Resolvido] Mapiar somente, mais não Cascatear

0 respostas
N

Bom dia!
tenho as classes;

@Entity
@Table(uniqueConstraints = {
    @UniqueConstraint(name = "uk_ficha_treino", columnNames = {"cliente_id", "dataLancamento", "letraTreino"})})
public class FichaTreino implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @NotNull(message = "O cliente deve ser infomado.")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "cliente_id")
    private Cliente cliente;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataLancamento;
    @Column(length = 1)
    private String letraTreino;
    @Cascade(CascadeType.ALL)
    @OneToMany(mappedBy = "fichaTreino", fetch = FetchType.LAZY)
    private List<FichaTreinoExercicio> fichaTreinoExercicios = new ArrayList<FichaTreinoExercicio>();

e

@Entity
public class FichaTreinoExercicio implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ManyToOne
    @JoinColumn(name = "fichatreino_id")
    private FichaTreino fichaTreino;
    @ManyToOne
    @JoinColumn(name = "exercicio_id")   
    private Exercicio exercicio;
    @Min(value = 0, message = "Série maior ou igual a zero")
    private Integer serie;
    @Min(value = 0, message = "Quantidade de vezes deve ser maior ou igual a zero")
    private Integer repeticao;
    @Min(value = 0, message = "Carga ser maior ou igual a zero")
    private Integer carga;
    @Min(value = 0)
    private Integer ordem;

essas entidades gerão as seguintes tabelas: Até ai tudo bem!

CREATE TABLE fichatreino
(
  id bigserial NOT NULL,
  datalancamento date,
  letratreino character varying(1),
  cliente_id bigint NOT NULL,
  CONSTRAINT fichatreino_pkey PRIMARY KEY (id),
  CONSTRAINT fk13a2ef1cb5dbe97b FOREIGN KEY (cliente_id)
      REFERENCES cliente (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fichatreino_cliente_id_datalancamento_letratreino_key UNIQUE (cliente_id, datalancamento, letratreino)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE fichatreino OWNER TO postgres;
CREATE TABLE fichatreinoexercicio
(
  id bigserial NOT NULL,
  carga integer,
  ordem integer,
  repeticao integer,
  serie integer,
  exercicio_id bigint,
  fichatreino_id bigint,
  CONSTRAINT fichatreinoexercicio_pkey PRIMARY KEY (id),
  CONSTRAINT fk7a436e476c6941db FOREIGN KEY (fichatreino_id)
      REFERENCES fichatreino (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk7a436e47f898849b FOREIGN KEY (exercicio_id)
      REFERENCES exercicio (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fichatreinoexercicio_carga_check CHECK (carga >= 0),
  CONSTRAINT fichatreinoexercicio_ordem_check CHECK (ordem >= 0),
  CONSTRAINT fichatreinoexercicio_repeticao_check CHECK (repeticao >= 0),
  CONSTRAINT fichatreinoexercicio_serie_check CHECK (serie >= 0)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE fichatreinoexercicio OWNER TO postgres;

reparem que na classe FICHA_TREINO eu coloquei :

@Cascade(CascadeType.ALL)
    @OneToMany(mappedBy = "fichaTreino", fetch = FetchType.LAZY)

mais preciso que esse relacionamento na Classe FichaTreinoExercicio exista MAS não CASCATEI
fique somente para mapear e pegar o código do EXERCICIO:

@ManyToOne
    @JoinColumn(name = "exercicio_id")   
    private Exercicio exercicio;

Obrigado!

Criado 9 de maio de 2011
Respostas 0
Participantes 1