• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Hibernate does not see manually inserted data

 
Greenhorn
Posts: 2
Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project on Spring Boot (v. 2.0.5), Hibernate (v. 5.2.17), Ehcache, Flyway, Solr.
There is the Problem with Hibernate:
https://stackoverflow.com/questions/54777017/hibernate-does-not-see-inserted-in-sql-script-data

Please, help me anybody!
I can not deal with this problem for 2 weeks. Concluded that the Hibernate is not convenient, unlike the JdbcTemplate and Jdbc.
 
Bartender
Posts: 20838
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can only guess, since I don't do it that way, but you've marked your DAO class as @Transactional, but you're doing an explicit flush. And, come to think of it, you're doing an awful lot of update-type things in what is supposed to be a "read" method.

You also didn't show the code that was actually supposed to persist the changes you'd made, which makes it hard to guess why it doesn't read back.

I believe that someone on StackOverflow also asked you basically to do an external query of the database via the psql command-line tool or an equivalent to determine if the database actually updated or not so that you can tell if the fault was in the writing or the reading back. That's advice worth following.
 
Evgeny Ageev
Greenhorn
Posts: 2
Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Eclipse in Database Development view I run an SQL query like this:

or like this:

And it presented.

And my EntityManager don't want to see the 103696 record.

Answer your question about insert - I inserted 2 rows in Database Development with help insert query:

And what about flush - before it was not presented and some other methods too. I added them because code not worked.

@Transactional was not presented. Then I added it, nothing was changed.

I was going to Google and see what my problem is not unique. Many people was collided with this problem for many years.
I don't know what to do with it.
 
Tim Holloway
Bartender
Posts: 20838
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you are actually doing there. If I code those statements into my PostgreSQL server, it comes back as "syntax error". Which is what I expected, since those statements make no sense. They're not in a "SELECT ... FROM tablename [WHERE...]" form, which is the norm for queries.

Your insert statement appears to have a schema.table name as its destination, and I'm not sure what a "help insert query" is supposed to mean, but if it means that you were using an external database client like the Eclipse Database Explorer, then no, I would not expect your application to always see that insertion. For one thing, you didn't commit the insertions, which means that they haven't been flushed from the database explorer program to the database, and therefore the changes are not yet "real", so Hibernate should not see them. And when I say "should not", I mean, that it would be a bug in either Hibernate or PostgreSQL to see data that hasn't been committed yet.

Even if the data had been committed, if you're doing the insert via the database explorer (or some other external application), then Hibernate would not see it if it was optimistically caching. However, the default for JPA is pessimistic caching, so it should have fetched once the insert had finished committing. All those flush and cache-clear things you are attempting are not only useless, but potentially could undo what you had done elsewhere, since flush() writes from the application to the database - it doesn't invalidate what the application thinks is already there.

As far as using a tablename in the form of "schemaname.tablename", I can say that Hibernate JPA has given me problems. But if I'm not mistaken, the main problem came from trying to work with 2 different schemas at once. Normal operation is to work with only one schema, and not to hard-code the schema name into the Entity class definition.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!