-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: OneToOne throw multipleBag exception,is it correct behavior?
PostPosted: Wed Jun 13, 2012 6:01 am 
Newbie

Joined: Wed Jan 12, 2011 1:15 pm
Posts: 11
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.