I am connecting to a MySQL table using JPA Hibernate. But I am getting error in my Java code:
org.hibernate.HibernateException: Missing table
My table is present in MySQL database schema. I am not getting why missing table exception is thrown here. This is a newly created table. All other existing tables in the same schema are accessible from Hibernate. I saw similar posts with same error. But the answers there didn't help my cause. Can you please let me know what can be the issue here.
If table is present, then most likely it is user permission issue. This happens if you have created the table using a different MySQL user. Make sure the MySQL username/password that you are using in Hibernate is having access to the table. To test, login to MySQL console directly using Hibernate credential & run a select query on the table. If you see similar error as below, then you need to grant access to the table for the Hibernate user.
ERROR 1142 (42000): SELECT command denied to user
Source: http://www.w3spot.com/2020/10/how-to-solve-caused-by-hibernateexception-missing-table.html
Make sure the user has access to the table
Make sure names are equals in terms of case sensitivity
Make sure the schema name and table name are not misspelled
If you share more information about the issue, it would be easier to pinpoint the problem.
Chances are there is an inheritance scenario with a physical table that you assumed to be abstract.
To dig deeper you can put a breakpoint in org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl#getTablesInformation which calls extractor.getTable to see why your table is not returned as part of schema tables.
Rerun the app with the specified breakpoint and step through lines to get to the line which queries table names from the database metadat.
#Override
public TableInformation getTableInformation(QualifiedTableName tableName) {
if ( tableName.getObjectName() == null ) {
throw new IllegalArgumentException( "Passed table name cannot be null" );
}
return extractor.getTable(
tableName.getCatalogName(),
tableName.getSchemaName(),
tableName.getTableName()
);
}
I am importing and exporting between two databases, and the problem when I want to add some tabels to the new it raises the error regarding the constrains.
I know how to turn this directly by using the mySQL:
SET FOREIGN_KEY_CHECKS=0
however, I want to use something like sission or query to send this command to the database.
I have tried something like this:
Query q = session2.createQuery("SET FOREIGN_KEY_CHECKS=0");
and this also didn't work.
I'm using hsql 2.3.3. According to documentation I can fix this either by adding additional statement to the sql
SET DATABASE SQL SYNTAX ORA TRUE
or by adding property to the url
url: jdbc:h2:mem:test;sql.syntax_ora=true
First one fixes the issue for me (so this is root cause of it), but I would like to use second one as it looks more generalized for me. But url property does't do the trick. What I'm missing?
The URL property works only if you create a new database with the connection property. The new database will then include the SQL statement and run it automatically at each startup.
I have been able to successfully create MS Access database tables from Java using the UCanAccess 2.0.6 driver. However, I am subsequently unable to open up the tables from MS Access (Microsoft Office 2007, Windows 7 64-bit), with MS Access throwing the error :
Reserved Error (-5001); there is no message for this error.
The exact same CREATE TABLE statement when used from within MS Access itself results in no problems. The strange part is, the tables are successfully created and data can be successfully added AND retrieved by query. So the tables are there in the underlying database, but Access isn't able to open them.
If it helps, one of the create statements I'm using is as follows:
CREATE TABLE tblMain (
ID COUNTER NOT NULL PRIMARY KEY,
Project INTEGER NOT NULL,
ItemNumber INTEGER NOT NULL,
DateCreated DATETIME NOT NULL,
ItemName TEXT NOT NULL,
ItemDescription MEMO NOT NULL,
OriginatorPerson TEXT NOT NULL,
DueDate DATETIME NOT NULL,
Closed YESNO NOT NULL,
ClosingComments MEMO NOT NULL,
Priority YESNO NOT NULL,
AssignedToCompany TEXT NOT NULL,
AssignedToPerson TEXT NOT NULL);
I can't reproduce this problem, neither with Access 2007 nor with Access 2010.
All works fine also with Access 2003. But it might happen with some access version...
It looks very similar to an issue that another user reported in the UCanAccess forum and that I fixed (yet, in that case, I wasn't able to reproduce this issue):
http://sourceforge.net/p/ucanaccess/discussion/help/thread/5a57b955/.
I'm pretty sure it's about the way UCanaccess(using the underlying jackcess) persists the column properties (e.g, default values, "required" and so on).
Could you try to re-execute your DDL avoiding to set "not null" where not needed, so on the column ID(Counter and PK)? And please, let me know your findings, I haven't another way to definitively fix this bug.
May be you need to grant privileges to admin:
GRANT SELECT, DELETE, INSERT, UPDATE
ON tblMain
TO Admin;
Run that query using UCanAccess 2.0.6 driver.
This is something that I've been scratching my head with - especially since it's infuriating to deal with.
Consider the following code:
String query = "UPDATE ORDERS SET VOLUME=?,CONTRACT_ID=?,PROJECT_ID=?,WORKSITE_ID=?,DROPZONE_ID=?,DESCRIPTION_ID=?,MANAGER_ID=?,DELIVERY_DATE=?,REVISION=REVISION+1) WHERE ID=?";
jdbcTemplate.update(query, orderEntity.getVolume(), orderEntity.getContractNo(), orderEntity.getProjectID(), orderEntity.getWorksiteID(), orderEntity.getDropzoneID(), orderEntity.getDescriptionID(), orderEntity.getManagerID(), orderEntity.getDeliveryDate(), id);
We can see that the SQL query is incorrect - and will therefore throw some SQL error but one might have missed that. Spring will (for me) throw a QueryTimeoutException in response to this. I'm sort of okay with that but it's not helpful.
Now let's try
String query = "INSERT INTO ORDERS(ID,REISION,CONTRACT_ID,PROJECT_ID,WORKSITE_ID,DROPZONE_ID,DESCRIPTION_ID,MANAGER_ID,VOLUME,DELIVERY_DATE) VALUES(?,?,?,?,?,?,?,?,?,?)";
jdbcTemplate.update(query, id, revision, etc);
Another spelling mistake that's easily missed - REVISION is misspelled as REISION) Spring throws another QueryTimeoutException again. This now means that if I get that exception I don't actually know what it is. Is it a syntax error? Is it a column spelling error? Is it the (much harder to notice) fact that the foreign key constraint not being followed?
While debugging, this is quite possibly the most infuriating thing ever - all I know is that my query failed to run. How can I get something useful? Is there something I've not added to my pom.xml file?
EDIT:
Here's a nicer example. I have a DESCRIPTIONS table, with an ID, REVISION and TEXT column. All of those are marked as not being nullable.
DescriptionEntity descriptionEntity = new DescriptionEntity("newDesc", 1, null);
String query = "INSERT INTO DESCRIPTIONS (ID,REVISION,TEXT) VALUES(?,?,?)";
jdbcTemplate.update(query, descriptionEntity.getID(), 1, descriptionEntity.getText());
That will also throw a query timeout exception, when running the query in mysql gives me ERROR 1048 (23000): Column 'TEXT' cannot be null
This is, to put it politely, a bit of a pain.
It's not a spelling mistake in the first example, as you left out the opening paren. I would say this isn't an issue with Spring or JDBC, but rather your DB is trying to process the SQL, waiting for more input or something, and never returning.
In the second one, I am not sure what you are talking about since I don't know the table design. I have to assume what you mean is ID is not unique? Again, I wouldn't blame Spring or JDBC, maybe the drive, most likely the database server.
Keep in mind, in a lot of cases, the way SQL is handled in the user Client UI is not the same as how it gets handled through JDBC. For instance, in SQL Server the SQL is set as a string, the passed in parameters set as variables, and it uses sp_executesql() to run it. I discovered that when I had a report that ran PERFECTLY fine through SQL Studio Manager client, but blew up when I ran it live because the query plan optimizer took a different path due to the differences in how the SQL was ran.
This is quite possibly the most stupid error I've ever come across: the issue was in how Maven resolved all the dependencies.
The requirement for Spring Security was placed before the JDBC requirement. That made Spring Security pull down org.springframework:spring-tx:jar:3.0.7.RELEASE:compile which satisfied the dependency for JDBC. Moving the JDBC requirement up meant JDBC pulled down org.springframework:spring-tx:jar:3.2.2.RELEASE:compile.