I have the following entity classes:
ClassA, ClassB and ClassC. ClassC extends ClassB which extends ClassA.
There is another entity class named ClassWithALongName.
ClassA has a many-to-one relationship with ClassWithALongName which is defined as below:
public class ClassWithALongName {
@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
private ClassA myClassA;
// getter-setter of myClassA
}
Let's say aClassC is a ClassC instance and the following lines are run:
org.hibernate.Session session = (Session)getEntityManager().getDelegate();
session.saveOrUpdate(aClassC);
session.flush();
After this, three update statements are run for ClassA, ClassB and ClassC which is expected.
What I didn't expect is a delete statement on a table that doesn't exist as so:
delete from ClassA_ClassWithALongName where ClassA_id=?
The last statement causes an exception because the actual classes have longer names and so the temporary identifier ClassA_ClassWithALongName has actually more characters. Because Oracle db prevents tables whose names have more characters than 30, it throws an exception.
I didn't understand two things. Why is this delete necessary when only update statements are run? Why does hibernate create such a temporary identifier which doesn't match with a table in the database.
Thanks for any hints.
As an answer to Justas comment, the exception is:
java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
Essex Boy's answer helped me solve the issue. The entities are very complex and someone added a list with a one-to-many association that I didn't notice. I still do not get why there is a need for a delete statement during an update but I will leave that for the moment :)