In the model I have a table that save images from noticies,activities etc. For example one noticie can to have three images zero a three images maximun. In the class I put @OneToOne each image will have one reference. In SQL the FK attributes can be null. And this mapping only work if I put FetchType.LAZY, if I delete this option Hibernate throw multipleBag exception.
This mapping is wrong? How fix this error?
imagen mapping
Code:
@Entity
@Table(name="D_IMAGEN")
public class Imagen implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="seqImagen",sequenceName="SQ_IMAGEN")
@GeneratedValue(generator="seqImagen",strategy=GenerationType.AUTO)
@Column(name="IDIMAGEN")
private Integer idImagen;
@Column(name="IMAGEN")
@Lob
private Blob imagen;
@Column(name="NOMBRE",nullable=false)
private String nombre;
@Column(name="EXTENSION",nullable=false)
private String extension;
@Column(name="TAM",nullable=true)
private Integer size;
@Column(name="POSICION",nullable=true)
private String posicion;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="FECHA",nullable=false)
private Calendar fecha;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="IDNOTICIA")
private Noticia noticia;
/*@OneToOne
@JoinColumn(name="IDACTIVIDAD")
private Actividad actividad;
@OneToOne
@JoinColumn(name="IDQSM")
private QSM qsm;
@OneToOne
@JoinColumn(name="IDPROPUESTA")
private PropuestaQSM propuesta;*/
/* Getters and Setters */
}
SQL code
Code:
CREATE TABLE "ADM_USER"."D_IMAGEN"(
"IDIMAGEN" Integer NOT NULL,
"IMAGEN" Blob NOT NULL,
"EXTENSION" Varchar2(12 CHAR) NOT NULL,
"TAM" Integer NOT NULL,
"NOMBRE" Varchar2(50 ) NOT NULL,
"FECHA" Timestamp(6) NOT NULL,
"IDNOTICIA" Integer,
"IDQSM" Integer,
"IDACTIVIDAD" Integer,
"IDPROPUESTA" Integer,
"POSICION" Varchar2(3 CHAR)
)
TABLESPACE "TS_PROYECTO"
/
ALTER TABLE "ADM_USER"."D_IMAGEN" ADD CONSTRAINT "FK_IMAGEN_NOTICIA" FOREIGN KEY ("IDNOTICIA") REFERENCES "ADM_USER"."D_NOTICIA" ("IDNOTICIA") ON DELETE CASCADE
......
......
......
I use Hibernate Core 3.5.6
Kind regards.