1

I want to make a relation one to many with the same class java using hibernate (spring data)

this is my code

@Data
@Entity
public class TemplateData implements Serializable{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ManyToOne
    private TemplateData div;
    @OneToMany(mappedBy="div")
    private Collection<TemplateData> baseCSS;

    private int position;
    private String data;

}

and I get this error

HHH000388: Unsuccessful: alter table add constraint template data FK_y1mi9blsbc08tmwm9jgvdd1b foreign key (template_data_id) references template_data
ERROR: "template_data" relationship does not exist
khalil _diouri
  • 791
  • 3
  • 12
  • 34

1 Answers1

-1

Sometimes this problem occurs when we use

hibernate.hbm2ddl.auto=create-drop

You can fix this by changing the hibernate.hbm2ddl.auto to update:

hibernate.hbm2ddl.auto=update

You can go through this tutorial.

Mikko Maunu suggested that

Combination of create-drop and in-memory database produces these for every database object it tries to drop. Reason being that there is not any database objects to remove - DROP statements are executed against empty database.

Also with normal permanent database such a errors do come, because Hibernate does not figure out before executing DROP statements does added object exist in database or is it new.

Resource Link:

Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132