views:

24

answers:

2

does insert query in hibernate requires table to be present. I mean when i have a query that insert some values in to the table which is not present . will the hibernate gives the exception or it will through the exception only when update is done .

I'm speaking in terms of only hibernate .

Can you please suggest

A: 

A table being present in terms of Hibernate doesn't make much sense in my opinion. A table is present in the database, or not. If it is not and if you have an Entity mapped on it, trying to persist this Entity will fail at flush time, when Hibernate will perform the SQL insert, and you'll get a HibernateException wrapping a JDBC exception.

If this doesn't answer the question, please clarify, I did not understand the part where you're referring to an update.

Pascal Thivent
A: 

I think you're asking if the table is missing will Hibernate throw the error or will the database throw the error.

IIRC, I don't think Hibernate will even initialize if the table is missing. You will get an error when its going through the mapping files and trying to pre-generate the CRUD SQL statements based on the datatypes in the database.

Javid Jamae
AFAIK, if you want Hibernate to validate the schema against the mappings at initialization time, you have to ask it to do so using `hibernate.hbm2ddl.auto=validate`. And I'll check this later but I don't see why Hibernate would use database metadata to generate the CRUD statements (the required informations are in the mappings IMHO). The question is pretty unclear anyway.
Pascal Thivent