-->
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.  [ 4 posts ] 
Author Message
 Post subject: OneToMany mistake
PostPosted: Mon Sep 08, 2008 11:33 am 
Newbie

Joined: Mon Sep 01, 2008 3:41 am
Posts: 19
Hi,

I need to do the @OneToMany.

I do like this:

Code:
package com.uw.diode.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import static javax.persistence.CascadeType.ALL;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="ReportCabecera")
public class CabeceraInforme implements Serializable {
   
   /**
    *
    */
   private static final long serialVersionUID = -3045888821211416269L;

   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "REPORTCABECERA_SEQ")
   @SequenceGenerator(name="REPORTCABECERA_SEQ", sequenceName = "reportcabecera_seq")
   @Column(name="Recab_IdReportCabecera", precision=10)
   private long id;

   @Column(name="Recab_Clave", length=20)
   private String nombre;
   
   @Column(name="Recab_Descorta", length=100)
   private String descripcionCorta;
   
   @Column(name="Recab_Deslarga", length=500)
   private String descripcionLarga;
   
   @Column(name="Recab_Area", length=20)
   private String area;
   
   @Column(name="Recab_Disponibledesde")
   private Date fechaInicio;
   
   @Column(name="Recab_DisponibleHasta")
   private Date fechaFin;

   @Column(name="Recab_Nomberuta", length=200)
   private String nombreRuta;
   
   @Column(name="Recab_Fegraba")
   private Date fechaGrabacion;
   
   @Column(name="Recab_Emgraba", length=20)
   private String empleadoGrabacion;
   
   @OneToMany(cascade = ALL, mappedBy = "ReportLogEjecucion", targetEntity=LogEjecucionInformes.class)
   private Collection<LogEjecucionInformes> logCollection;
   
   public Collection<LogEjecucionInformes> getLogCollection() {
      return logCollection;
   }

   public void setLogCollection(Collection<LogEjecucionInformes> logCollection) {
      this.logCollection = logCollection;
   }

   public long getId() {
      return id;
   }

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

   public String getNombre() {
      return nombre;
   }

   public void setNombre(String nombre) {
      this.nombre = nombre;
   }

   public String getDescripcionCorta() {
      return descripcionCorta;
   }

   public void setDescripcionCorta(String descripcionCorta) {
      this.descripcionCorta = descripcionCorta;
   }

   public String getDescripcionLarga() {
      return descripcionLarga;
   }

   public void setDescripcionLarga(String descripcionLarga) {
      this.descripcionLarga = descripcionLarga;
   }

   public String getArea() {
      return area;
   }

   public void setArea(String area) {
      this.area = area;
   }

   public Date getFechaInicio() {
      return fechaInicio;
   }

   public void setFechaInicio(Date fechaInicio) {
      this.fechaInicio = fechaInicio;
   }

   public Date getFechaFin() {
      return fechaFin;
   }

   public void setFechaFin(Date fechaFin) {
      this.fechaFin = fechaFin;
   }

   public String getNombreRuta() {
      return nombreRuta;
   }

   public void setNombreRuta(String nombreRuta) {
      this.nombreRuta = nombreRuta;
   }

   public Date getFechaGrabacion() {
      return fechaGrabacion;
   }

   public void setFechaGrabacion(Date fechaGrabacion) {
      this.fechaGrabacion = fechaGrabacion;
   }

   public String getEmpleadoGrabacion() {
      return empleadoGrabacion;
   }

   public void setEmpleadoGrabacion(String empleadoGrabacion) {
      this.empleadoGrabacion = empleadoGrabacion;
   }
   
   
}


But I'm not sure that what I need to put in mappedBy, if is the name of the table, the field or what...

The fact is that when I put the Annotation and run the application it's not works.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2008 12:08 pm 
Newbie

Joined: Mon Sep 01, 2008 3:41 am
Posts: 19
The problem is solved.

I put this In the first table:

Code:
@OneToMany(fetch=EAGER)
@JoinColumn(name="FK_LOGCABECERA")
@NotFound(action=IGNORE)
private List<LogEjecucionInformes> logEjecucionInformes;


and in the other one:

Code:
@ManyToOne(fetch=EAGER)
   @JoinColumn(name="RELOGEJE_IDREPORTCABECERA", insertable=false, updatable=false)
   @NotFound(action=IGNORE)
   private CabeceraInforme cabeceraInforme;


Thank you for all,

Praedos


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 8:26 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed.

Your mapped-by attribute is going to tell Hibernate how instance variables are used to map an association between one class to another.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 4:49 am 
Newbie

Joined: Mon Sep 01, 2008 3:41 am
Posts: 19
Thanks you Cameron


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

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.