开发者

What is managed and unmanaged environment mean in hibernate?

I'm new to hibernate. Can anybody explain me what it means when we say, 'Hibernate works in managed and unmanaged environment'?

What is managed and unmanaged environment mean?

Thanks in advance开发者_开发知识库,

-Uday


I am not sure about specific context you heard it in. But usually when we say 'managed environment' it means that there is some external container that operates things on your behalf. And in 'unmanaged' case you have do do work to manage your object lifecycle yourself.

For example, if you just use Hibernate by itself, you would need to create session, do your operation and close session. So it is unmanaged since you have to manage it yourself.

However, if you use Hibernate inside Spring container, session open and close will be taken care of for you by Spring. In this case, it is managed for you.


When writing Java code, it’s useful to differentiate between two types of targets: a “normal” environment and a “managed” environment. The difference between the two is simple. In a normal environment, you (the person writing the code) call the main() method. In a managed environment, you do not. Managed environments are sometimes called container environments because they usually follow a containment or hosting model. In this model, the host container is the code that contains the main() method, and independent units of third-party code (hereafter plugins) are managed by the container.

Take a look here: http://benpryor.com/blog/2007/10/14/managed-environments/


Managed environment is the one in which transaction management, security and database connection pooling is done either by the application server or by the managed resources like external 3rd party JTA api's like JBossTM. Thus relieving hibernate from these responsibility. To make hibernate work in a managed environment you need to specify the underlying transaction manager you want to use in hibernate configuration.

Non-managed environment is the one in which the application uses resource adapters to connect to underlying database connections, transaction management and security features without the use of application server. You don't have to specify transaction manager in hibernate configuration, the default hibernate's JDBCTransaction is used.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜