开发者

EclipseLink can't retrieve entities inserted manually

开发者 https://www.devze.com 2023-03-16 16:12 出处:网络
I\'m having some trouble with EclipseLink. My program has to interact with a database (representing a building). I\'ve written a little input-testmode where I can manually insert stuff through the con

I'm having some trouble with EclipseLink. My program has to interact with a database (representing a building). I've written a little input-testmode where I can manually insert stuff through the console开发者_如何学JAVA.

My problem: a normal getByID-operation works just fine if I try to retrieve an entity I previously inserted through EclipseLink itself (by commit()), but throws a NoResultException when trying to select a row manually inserted via SQL-script (building -> lots of rooms -> script).

This (oversemplified) works fine:

main() {
  MyRoom r = new MyRoom();
  r.setID("floor1-roomnr4");
  em.commit(r); //entity manager
  DAO.getRoomByID("floor1-roomnr4"); // works
}

and the combination of generation-script + simply getRoomByID() throws an exception.

If I try it in SQL Developer I get the result I want for the exact select statement which just threw a NoResultException. I also only get this problem in the input-mode, otherwise selecting the generated rows works also fine.

Does EclipseLink have some cache-mechanism I'm unaware of which is causing some problem?


Are you sure EclipseLink and SQL Developer are connected to the same Database? Please verify the connection information for both. Is the generation-script committing the changes with the "commit" command?


If EclipseLink works similarly to Hibernate then yes there is a cache. The "first level cache" guaranties that you get the exact same instance within one transaction which makes sense. If you know EclipseLink/transactions then try to evict all loaded instances or commit the transaction and then try your DAO again. This would force EclipseLink to fetch the data from the database again

See Answer to similar question

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号