Eclipse AWS Explorer can't see Dyanmodb tables created with Java - java

I'm trying to use AWS Explorer in Eclipse but it doesn't show newly created tables. When I use this Java sample code to create a table AWS Explorer doesn't show the new table after refreshing. It doesn't show it in either the local or us-west-2 region. If I run the code again it throws an Exception saying "Cannot create preexisting table ..." so the Movies table was created. If I change the second parameter in
new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")
by deleting the '2' I can run again successfully. Running a second time gives the same error.
What does the second parameter to EndpointConfiguration() do? It doesn't have to be a valid region name. Is this supposed to correspond to one of the regions in the AWS Explorer region drop list? Why do I need a region if I'm running locally? The second parameter does something since changing it allows me to create another table, but having it be a region name just muddies the waters. Apparently it can be anything. The JavaDoc is no help on this.
The Java code apparently is creating the Movie table somewhere else than AWS Explorer is looking. I've also tried RazorSql and it doesn't see the Movie table either. Both see tables created with AWS Explorer though.
Where does the Java code create its tables?

Try this for the client line:
new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "local")
I figured it out by checking what .db files were being created for the version of DynamoDB that I'm using. I saw one with "us-west-2" and another with "local". I decided to give "local" a try as the region and it worked! I can now see tables that were created using the "local" region.
I've posted a comment on the Amazon DynamoDB Developer guide explaining the need for an update to their code examples.

Related

Checking existence of a sqlite db in Android

When my app runs it first checks for the existence of the db. The first time it runs the db should not exist and if that's the case it will create the dB's tables, then it will populate specific tables with various support data. So, in testing this works fine. So I then delete the db through adb shell. Then I rerun the app and it determines that the db still exists!! I have 2 different methods that checks existence, or not,and both behave in the same aberrant way.
Method 1 simply tries to open the db as a Java file and then uses the exists method to check. Method 2 is a bit more elaborate using the db path and name as args to thedb.open database method.
Both methods fail to determine that the db does not exist, after I delete it in adb shell.
I can provide the code if needed, but thought I'd see if there are some ideas for this behavior. I have cycled the genymotion emulator but this did not fix it.
Thanks for any suggestions.
No. I stop the app, delete the db, then restart (All in Android Studio). By the way. Do you know why the db path, as reported by Gene motion, is not the same as my apps db path? Both tho do point to the same db, as shown in adb.

Cannot get Google Drive App Data folder content using query anymore

For some reason the following Android app code
com.google.api.services.drive.Drive drive;
...
drive.files().list().setQ("mimeType='application/vnd.google-apps.folder' and 'appdata' in parents").execute().getItems();
started returning empty list since May 14. This code was returning my custom folders for more than 1 year before.
I can see my App Data content still exists through
https://drive.google.com/drive/my-drive > Settings > Manage Apps.
Any ideas what is wrong?
This was a caching issue specifically for App Folder content that affected list queries.
The issue has now been rectified. Thanks for reporting.
Writes were not affected.
The issue still occurs. LIST method doesn't work for newly created files in Application Data Folder. After few hours LIST method returns those files.

JPA Cannot resolve column/IntelliJ

I'm trying to map some Java classes using the Hibernate JPA implementation. My problem is that I can't use hardcoded Strings als column namens. You can see the error message I get in the picture below.
I'm using OpenJPA as my Default JPA Provider and have already tried to change it.
IntelliJ Version 14.0.3
regards,
You have to associate your data source (create a data source in database view first - aka your real JDBC database connection) with a persistence unit or session factory (hibernate.cfg.xml).
Follow below steps and the warnings will disappear:
Open the Persistence tool window (View | Tool Windows |
Persistence).
Right-click the necessary module, persistence unit or
session factory, and select Assign Data Sources in the context menu.
In the Assign Data Sources dialog that opens, click the Data Source
field and select the necessary data source. (To remove the
association with the data source, select none.)
See here: Associating data sources with session factories and persistence units
For those who just want to disable this check, go to
Intellij IDEA -> Preferences -> Search "Unresolved database references in annotations" and uncheck it.
(macOS Mojave and Intellij Ultimate 2019.3)
This will disable the inspection and remove all the "Cannot resolve column…" errors on the #Column annotations. Intellij will stop checking if the String column names exist in the database tables. Do it at your own risk.
I found Panos' answer useful, but I didn't see anybody mention adding the database as a data source. Perhaps that's routine enough to be assumed, but if not, here's what I had to do:
Select View/Tool Windows/Database
The Database window usually appears on the top right.
In the Database window, click the green + sign and select Data Source/MySQL (or whatever flavor of Data Source you're using).
The Data Sources and Drivers window pops up.
If your database isn't listed there, use the empty form to add the following:
Host: usually localhost, but if your test database is living
on another machine, put that address in.
Username: for your database use.
Password: for your database user's password.
IDEA might need some fiddling to find the JDBC driver. I was told that in theory it should have found it in the maven build process for the project I was working on, but it did not. I reopened View/Tool Windows/Database and looked at my MySQL entry. At the bottom it had an error message next to Driver:, and also a MySQL link. I clicked the MySQL link and IDEA brought up a popup to fetch Connector/J.
Despite the fact that the checkboxes for Auto commit and Auto sync defaulted to checked and I left them that way, IDEA seemed to need a nudge. Or perhaps it was just taking a while and I was impatient.
In any event, first I double-clicked on the line for my database in Database. That seemed to do it, but I didn't realize I needed Persistence yet, and while sorting that out, at a coworker's suggestion, I also clicked the Synchronize button (two arrows in a circle) on Database.
You can also right-click on your database in Database and select Synchronize.
It may take a few seconds, but you should see IDEA filling in the database schema under the entry in Database.
Finally I found Panos's answer and fixed Persistence.
Select View/Tool Windows/Persistence
The Persistence window usually appears on the top left.
In the Persistence window, right-click on your project and select Assign Data Sources.
IDEA pops up a dialog with two columns, your project in the left column and in my case an empty cell in the right column. Click on the empty cell and IDEA should give you a dropdown that allows you to select the database you just added.
Again, it may take a few seconds for IDEA to finish analyzing the data source and redo all the inspections.
Just for anyone else whom this didn't solve and comes across via google (like myself) .. setting the table name via the #Table Annotation fixed it for me.
Actually this is not any error that prevents your code to compile. Probably your spell-checker is on and which gives you the spelling mistake. If you can compile your code then you may ignore these type of scenario.
Look you have not getting any error for other text like #Column, #GeneratedValue etc. That means jars using these kind of stuff are in your build path. So I think you can ignore these type of error.
maybe this solution also help someone...
Open Database dialog window from the right side of Intellij
Go to DB Data Source Properties (find it in top menu)
Go to Schemas
Uncheck "Default database"
Check your specific DB and inside also check Default schema(public)
Good luck!
If you are using the JPA, it is also important to set up the SQL Dialect as
HSQLDB instead of MySQL. This is often confusing because it feels like MySQL is the correct dialect, but in fact what you are dealing with hibernate is HSQL.
If you have just upgraded to IntelliJ 2017.13 or other derivatives of this version (e.g., Webstorm), or you've just re-imported your project, it might mess up the language injection and need to manually correct this.
This can be accomplished via the Project
Settings -> Languages and Frameworks
part of the IDE.
If there is no real mismatch and this warning happens just because of IDE, you can easily link your project with the data source that you connect. Intellij already suggests the way to do it.
I'm using Intellij and connecting DB by JPA. I've met problem just like you and this is my solution.
You need to connect your database following these steps:
View -> Tool Windows -> Database -> then add database you are using to Intellj
After connect your database, you need to assign data source to Intellj by following these
View -> Tool Windows -> Persistence -> then add data from database you just added from 1 step
OK. That's all!
P/s: make sure your code work well!

How to import an existing database into netbeans

I had created a database using mysql workbench and i saved that database in one of the local drives. So in netbeans I need to design a database which is same as the earlier (created by using mysql workbench). So I would like to import that database into netbeans. Can anyone explain the procedure to do so?
A couple of days back I faced the same problem and found a easy solution. Though this question is asked 2 years back, I am posting this answer because it still doesn't have an answer here, so that it can provide help to other people with same problem in future.
I assume you know how to configure MySQL server. If no, visit https://netbeans.org/kb/docs/ide/mysql.html and follow the 'Configuring MySQL Server Properties' part.
After you create the server, right click on the 'MySQL Server'->'Create new database'. Give the database same name as the existing database has.
Now create a connection to the newly created database. If you dont know how, see the 'Starting the MySQL Server' and 'Creating and Connecting to the Database Instance' from https://netbeans.org/kb/docs/ide/mysql.html.
Now Expand the newly created connection which will look like 'jdbc:mysql://localhost:(portNumber)/(databaseName)'. Expand the database name node and right click 'table' and select 'Execute Command'
A new window will open. Assuming that you have a .sql file(Or may be a file without extension but consisting of SQL commands. You can export the database in file using your current admin tool if you have not already). Open that file in editor(notepad) and copy paste everything in the new opened command window in Netbeans.
Before Executing, just add one line before which states which database to use to execute query on.
USE <newly_created_database_name>;
as shown in the screenshot below (Red mark), it should be before the first line of the copy pasted SQL commands.
Now Execute the commands using the 'run SQL' button (green mark in image). To check, expand the tables node to see all the tables in original database are created.
Now you have your original database in place to work with.
You can use the built-in tools.
With your NetBeans project up, click new file and search for a persistence unit.
Follow the prompts entering the corresponding information(ie, host info, username, password, etc).
Once completed, go back in your project view and click on the services tab. You should see the database connection there.
To add them to your project, go back to your project tab and add a new file of type "Entities Classes from Database" the next prompts will ask you what tables to import and such.
Once completed, NetBeans will auto import all tables with getters and setters.
Here is a succinct example from Official Documentation: https://platform.netbeans.org/tutorials/nbm-crud.html#creating-app

Database record reverting after manual change

Problem solved: Thanks guys, see my answer below.
I have a website running in Tomcat 5.5 hooked up to a MySQL5 database using Hibernate3.
One record simply refuses to keep any changes performed on it. If I change the record programmatically, the values revert back to what they were previously.
If I manually modify the record in the database, the values will revert (seemingly once the webapp accesses them).
I have tried stopping Tomcat and changing the values manually then starting Tomcat again. Checking the database, the values remain changed after Tomcat has started the webapp but will revert back again once I load the site.
I have also tried deleting the Tomcat work folder for the webapp and the .ser cache file.
I have also checked the code for the values that are being reverted to and cannot find them.
I have only noticed it on this one particular record.
Edit: I've just had a look at the SQL output from Hibernate using hibernate.show_sql=true. There is an update query logged for the table my row is in. Does anyone know how to resolve the ? for the columns to actual values?
You could temporarily enable the mysql query logging and see exactly what sql statement altered the value. Since you say it changes immediately after the server starts you should be able to figure out the statement pretty quickly.
http://dev.mysql.com/doc/refman/5.0/en/query-log.html
To answer your question:
Does anyone know how to resolve the ?
for the columns to actual values?
You can do this with p6spy. Instructions for how to set this up in a Spring app are available here.
However, I think there's a mistake in these instructions, the file they refer to as p6spy.log should actually be name p6spy.properties.
It's getting close to halloween, so you have to expect this sort of thing (plus it was just a full moon), but I'd keep looking for the culprit in the web application ... it HAS to be there. A couple values I'd immediately search for in the webapp source code:
The id of the record being changed.
The value that's being written into
the record.
Good luck ... these can be real bears to find!
This smells a little like a test-case firing on start up that modifies the row to what it expects it to be before testing.
Add a trigger BEFORE UPDATE, check row id, raise an SQL error if it matches your magic row.
Then check the generated stacktrace, walk the code and locate the piece that updates the row.
Thanks to everyone for the help. All of the suggestions came in handy for tracking it down.
I've managed to find out what was causing it. Bad database design, multiple data models and Hibernate makes for some nasty stuff. Another table had the value stored and that class was extending a base class with the same value.
Time to look at doing some normalisation.

Categories