首先在Hibernate项目中放置addAnnotatedClass() [英] First Hibernate project where to place addAnnotatedClass()

查看:140
本文介绍了首先在Hibernate项目中放置addAnnotatedClass()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all
我试图建立一个Web应用程序的第一个Hibernate项目,但我有一些问题
试图找出方法的位置:

Hello all I'm trying to build up my first Hibernate project for a Web app, but i'm having some issues Trying to find out where to place the method:

AnnotationConfiguration config = 
            new AnnotationConfiguration();

config.addAnnotatedClass(Object.class);

config.addAnnotatedClass(Object.class);

config.configure();

config.configure();

我有一些java bean装饰注释,shel我只是插入到同一个类中的bean是?

i have some java beans decorated with annotations, shel i just insert it in the same class there the bean is?

谢谢

推荐答案

理想情况下,开发独立应用程序。在Java EE环境中,您只需在部署存档中定义一个persistence.xml文件(或hibernate.cfg.xml),容器(如JBoss AS)将使@PersistenceContext(EntityManager)可用。

Ideally, you'd call this only if you are developing a standalone application. In a Java EE environment, you'd just define a persistence.xml file (or hibernate.cfg.xml) in your deployment archive and the container (like JBoss AS) would make a @PersistenceContext (EntityManager) available to you.

在独立应用程序中,您可以在Bootstrap代码中调用此方法。

In a standalone application, you'd call this in your "Bootstrap" code. The one which sets up the environment.

在非Java EEWeb应用程序中(严重的,谁仍在使用?),你必须诉诸一些hacks,像在上下文启动期间做一些初始化(所以你不需要为所有请求运行这个,因为它是一个昂贵的操作)。

In "non-Java EE" web applications (seriously, who still uses that?), you'd have to resort to some "hacks", like doing some initialization during context startup (so that you won't need to run this for all requests, as it's an expensive operation).

这篇关于首先在Hibernate项目中放置addAnnotatedClass()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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