La tabla o vista no existe después de la generación de Hibernate SQL

My current Hibernate project is having some mapping problems. But first of all, I'll tell that I'm using:

NetBeans 7.1.1
Oracle 10g
Apache Tomcat 7.0.22
Hibernate 3.2.1

I have to say that all the mapping classes were generated by the Hibernate Reverse Engeneering Wizard usar Anotaciones, I mean, the classes were built from the tables at the database. I can run the program properly except the part regarding the insertion in a OneToMany relationship, this one:



  @Table(name = "EXP_EXPEDIENTES")
  public class ExpExpedientes implements Serializable {

  @SequenceGenerator(name = "seq", sequenceName = "EXP_SEQ") //Triggers are disabled so Hibernate can manage the sequence generation.
  @GeneratedValue(generator = "seq")
  @Column(name = "ID_EXP")
  private long idExpediente;

  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  private Set<ExpInstrucciones> expInstrucciones;    

  //more fields
  //getters & setters


  @Table(name = "EXP_INSTRUC")
  public class ExpInstrucciones implements Serializable {

  @Column(name = "ID_INS")
  private long idInstruccion;

  @JoinColumn(name="ID_EXP", nullable=false)
  private ExpExpedientes expExpedientes;

  //more fields
  //getters & setters

This way, I can make an ExpExpediente object and several ExpInstrucciones objects. After assigning some values and before trying to save them, I do:

  /* Previously, I've created these objects:
   * expInst_1 = new ExpInstruccines();
   * expInst_2 = new ExpInstrucciones();



Programas de ahorrar method in the DAO class just consists on And here is where my problems come. Reading the sql generated by Hibernate, I could find out that the ORA-00942: table or view doesn't exist error appears when Hibernate try to execute the next sentence:

      (EXP_EXPEDIENTES_ID_EXP, expInstrucciones_ID_INS) 
      (?, ?)

I think the error is related to the table EXP_EXPEDIENTES_EXP_INSTRUC, which obviously does not exist in the database. In fact, the mapping was generated from the database, as I already said.

And now, my question: Am I supposed to create that table? Or all this issue is due to a misconfiguration problem? I really don't know what to do, so any help will be appreciated.

preguntado el 28 de agosto de 12 a las 11:08

1 Respuestas

Your mapping should look like this:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, 
   mappedBy = "expExpedientes")   
private Set<ExpInstrucciones> expInstrucciones;     

Sides of bidirectional relationship should be connected using mappedBy atributo en @OneToMany side, otherwise you'll have two unidirectional relationships between ExpExpedientes y ExpInstrucciones, one of them implemented using foreign key and another one - using join table (by default).

I guess it's an error of Hibernate Reverse Engeneering Wizard, you should check other relationships for this problem as well.

Respondido 28 ago 12, 12:08

Thanks a lot. That works. I had tried the mappedByattribute, with no result, on the other side of the relationship. Thanks again. - Julio

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.