JPA Eclispelink - unable to retrieve the last inserted record - caching

I've a problem with JPA EclipseLink.
I've two functions: First, it inserts a row in the database correctly.
The second reads all the values ​​in the same table and show them to you. The problem is that it shows all the values ​​except the last quote, in order to make this appear, I must close and reopen the application.
I also tried to disable the cache does not work.
Do you have any idea on how to solve?
Thanks

How are you querying the quotes? Are you accessing a OneToMany, or using a query?
If accessing a OneToMany, then it could be a caching issues, which you can disable to check,
http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F
A query should always get all objects from the database. Ensure you committed the inserted objects.
The refresh a specific query see,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching#How_to_refresh_the_cache

Related

oracle forms 6i frm-40301 query caused no records to be retrieved

I have created sales master and sales detail (master/detail) relationship form.
I have entered record and saved it ...
Through another form, i hv updated few fields of sales_master table .. see below example
During data entry - Like ... Sal_OrdStatus = 'Open' and CashRcvd_Status='P'
Updating these fields through payment form Sal_OrdStatus = 'Closed' and CashRcvd_Status='R'
After this, when I am entering/execute those records where both fields are updated
then see below error even record is available in the database/table
frm-40301 query caused no records to be retrieved, re-enter
enter image description here
Please advise solution/ guideline
Thanks
Javed Akram
Querying data block won't return anything if there are no rows in the table at all, or if condition you set prevents any rows to be retrieved.
As some rows obviously exist (you updated them, not deleted), then it is the latter.
Use get_block_property built in and its last_query property (you can try default_where as well) to see which query was really executed; you'll see the where clause, and that should help you find the culprit. Once you know it, you'll be able to fix it.

Spring Data Mongo: dropCollection doesn't remove collection completely?

Code:
template.dropCollection("products");
After code execution, I see that all documents from collection products were removed, but collection by itself still exists.
So, the question then is how to drop collection completely?
Note: spring-data-mongodb:2.2.10.RELEASE
Mongo DB 4.2.12.
There is a refresh button when you use MongoDB Compass.
Check the collection names, it is already dropped.
System.out.println(template.getCollectionNames());
template.dropCollection("products");
System.out.println(template.getCollectionNames());

JPA add a condition to every single query automatically

Before anything, i must say this first: This table design is not my decision. We protest but to no avail, so please don't tell me, don't create a table like that.
We have a database with each table have a flag. This flag used to indicate which environment this row belong to, production or test data.
For server side, we have one variable which currently stored in ThreadLocal to indicate which environment this request belong to, same value as the flag in database.
Our requirement is that if my request belong to test environment then we must select only record belong to this environment. We would need to add a condition to every query we made to database, something like:
SELECT t FROM TABLE t WHERE t.flag = :environment
But we have to update every single query, update every object to set this flag before insert/update into database. This will require a lot of effort as our system already built long ago, not on progress. Also this will bring a lots of risk if someone forgot to add this to any new query.
So is there anyway to insert a condition to check this flag value for every query without have to manually edit the query string? Like an interceptor or something to put this condition in?
Which JPA provider?
With Hibernate, you could try using a #Filter.
Multitenancy could be another option, but probably an overkill in your scenario.
Finally, since you flagged the question with Oracle, perhaps the easiest approach would be to provide dedicated schemas (per environment) with views for every single table in your db, filtered by the flag column. Not sure if you're allowed to do that, though.
With some of the above, you would need a global entity listener to populate the flag field of your entities before they are persisted.

mutual exclusion in joomla

I created an extension for joomla using:
$id=$database->insertid();
I just covered that if two users are logged on to the site will fit together perform two records in the database and then this statement will return in both cases the same value.
in php you can solve this problem with the transactions.
In joomla how do I solve this problem?
If you have a table you are working with that extends JTable then make sure that you included the check out functionality that is optionally a part of that. THis must means adding a couple of fields like what is in the content table. This will prevent two people from editing the same row at the same time which creates a race condition in which one of the other will lose their data.
Please note that both php and joomla functions to return the last insert id rely on the mysql implementation, and mysql returns the last id inserted on the currently open connection so concurrency is not an issue
#iacoposk8 Your are right it might possible that in very rear case. Such time try to add current logged in user id in your sql query or any where so that it doesn't make any confict. I hope you get it what i want to say. Thanks

Getting SqlCeException on restart if I don't insert data to the DB

Basically, I have a LINQ database context and its model. As usually, I create the DB in the SQL context if the DB does not exist (the context is a singleton and on every access to it, this is checked).
Everything works well if I add data to the DB on the first launch. But if I don't insert any data during the first start of the app, on successive launches I get
SqlCeException:The specified table does not exist [TableName]
I don't know how more specifically I can explain it, but the exception comes immediately whenever I do a LINQ query on the second launch of the app if I don't insert any data on the first launch. If i do insert some data during the first launch, all is fine for the rest of the app's life time. Why would it be a bad thing to create the DBs and introduce the DB context, but not insert any data?
Here's my LINQ DB model:
https://github.com/kypeli/Podcatcher/blob/master/wp7/Podcatcher/ViewModels/PodcastSubscriptionModel.cs
Here's where I get the exception on second start if I didn't insert any data on the first launch:
https://github.com/kypeli/Podcatcher/blob/master/wp7/Podcatcher/PodcastSqlModel.cs#L64
It also strikes me that there's no API call to check if a table exists or not in LINQ, so I would have to assume "this should just work" - but it doesn't.
Any ideas? Thanks! :)
Update: I verified analyzing the .sdf file that indeed there are no tables created if I don't insert any data upon first launch of the app. As I see it:
This is a bug in LINQ-to-SQL. It should not crash if there are no tables present, but know that it should create them. Or deal with the case and create tables only when data is inserted.
I would need to insert some dummy data into SQL always on first launch, or...
Check if a table exists, if not, react to it by forcing LINQ-to-SQL to create them. But how?
I've dealt with this problem also, I've fixed it this way:
get the data context:
dbDataContext = new DBDataContext(DBConnectionString);
if( dbDataContext.DatabaseExists() == true)
//then try to get an entity:
System.Data.Linq.Table<Entity> entities = dbDataContext.Tablename;
//try to get an element from the entity:
IEnumerator<Entity> enumEntity = entities.GetEnumerator();
entities.GetEnumerator(); will always raise the exception "Table not found."
Just use a try/catch and in the catch scope delete the db and recreate it, because your DB is empty anyway :)
dbDataContext.DeleteDatabase();
dbDataContext.CreateDatabase();
dbDataContext.SubmitChanges();

Resources