EclipseLink文档没有解释“会话”。 [英] EclipseLink Document Doesn't Explain "session"

查看:45
本文介绍了EclipseLink文档没有解释“会话”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照 http:// wiki上糟糕的文档,尝试使用EclipseLink执行查询。 eclipse.org/Introduction_to_EclipseLink_Expressions_%28ELUG%29 ,但是每次您需要执行一个Expression时,它都使用一个名为 session的变量,但是没有说明该 session变量的来源。我已经有了一个persistence.xml文件,并且可以在数据库上运行javax.persistence.Query,因此我知道该连接有效,但是我无法确定会话的来源。

I am trying to execute a query using EclipseLink following the crappy documentation at http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_%28ELUG%29, but every time you need to execute an Expression it uses a variable called "session", but no where does it explain where this "session" variable comes from. I already have a persistence.xml file and I can run a javax.persistence.Query on my database, so I know the connection works, but I can't figure out where "session" comes from. A little help please?

一个小问题:我一直在努力使EclipseLink正常工作,尽管每个人都说它与Hibernate相比有多么出色。 EclipseLink是值得我的时间和沮丧吗,还是应该只是将其报废并尝试使用类似Hibernate的东西?

A side question: I have been having a terrible time trying to get EclipseLink to work, even though everyone says how great it is compared to Hibernate. Is EclipseLink worth my time and frustration, or should I just scrap it and try something like Hibernate instead?

谢谢

推荐答案

我建议阅读

在EclipseLink中,存在各种会话。无需赘述,
可以说会话就像是交易。在EclipseLink中,会话通常是一个工作单元,它知道哪些实体已更改/添加/删除或进行任何操作。

In EclipseLink, there're differents kinds of sessions. Without going into the details, you can say that a session is something like a transaction. In a EclipseLink, a session is often a Unit Of Work, which knows what entities have changed/added/deleted or whatever.

您可以在EclipseLink中检索此类会话,在JPA EntityManager上调用以下专有API时:

You can retrieve such a session in EclipseLink, when invoking the following proprietary API on your JPA EntityManager:

//EntityManagerImpl has to be imported as org.eclipse.persistence.internal.jpa.EntityManagerImpl
Session session = ((EntityManagerImpl) entityManager).getActiveSession();

在调用此功能之前,您应确保自己在交易中。

Before calling this, you should be sure that you're within a transaction.

这篇关于EclipseLink文档没有解释“会话”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆