📄 tutorial.po
字号:
"single-threaded unit of work, the <literal>SessionFactory</literal> is a ""thread-safe global object, instantiated once."msgstr """몇몇 <literal>Event</literal> 객체들을 로드시키고 저장할 차례이지만, 먼저 우""리는 어떤 인프라스트럭처 코드로 설정을 완료해야 한다. 우리는 Hibernate를 시작""해야 한다. 이 시작은 전역 <literal>SessionFactory</literal> 객체를 빌드하고 ""어플리케이션 내에서 용이한 접근을 위해 그것을 어떤 곳에 저장하는 것을 포함한""다. <literal>SessionFactory</literal>는 새로운 <literal>Session</literal>들""을 열 수 있다. <literal>Session</literal>은 작업의 단일-쓰레드 단위를 표현하""며, <literal>SessionFactory</literal>는 한번 초기화 되는 하나의 thread-safe ""전역 객체이다."#. Tag: para#: tutorial.xml:346#, no-c-formatmsgid """We'll create a <literal>HibernateUtil</literal> helper class which takes ""care of startup and makes accessing a <literal>SessionFactory</literal> ""convenient. Let's have a look at the implementation:"msgstr """우리는 시작을 처리하고 <literal>Session</literal> 처리를 편리하게 해주는 ""<literal>HibernateUtil</literal> helper 클래스를 생성시킬 것이다. 이른바 ""<emphasis>ThreadLocal Session</emphasis> 패턴이 여기서 유용하며, 우리는 현재""의 작업 단위를 현재의 쓰레드와 연관지워 유지한다. 구현을 살펴보자:"#. Tag: programlisting#: tutorial.xml:352#, no-c-formatmsgid """<![CDATA[package util;\n""\n""import org.hibernate.*;\n""import org.hibernate.cfg.*;\n""\n""public class HibernateUtil {\n""\n"" private static final SessionFactory sessionFactory;\n""\n"" static {\n"" try {\n"" // Create the SessionFactory from hibernate.cfg.xml\n"" sessionFactory = new Configuration().configure().""buildSessionFactory();\n"" } catch (Throwable ex) {\n"" // Make sure you log the exception, as it might be swallowed\n"" System.err.println(\"Initial SessionFactory creation failed.\" + ""ex);\n"" throw new ExceptionInInitializerError(ex);\n"" }\n"" }\n""\n"" public static SessionFactory getSessionFactory() {\n"" return sessionFactory;\n"" }\n""\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:354#, no-c-formatmsgid """This class does not only produce the global <literal>SessionFactory</""literal> in its static initializer (called once by the JVM when the class is ""loaded), but also hides the fact that it uses a static singleton. It might ""as well lookup the <literal>SessionFactory</literal> from JNDI in an ""application server."msgstr """이 클래스는 (클래스가 로드될 때 JVM에 의해 한번 호출되는) 그것의 static 초기""자 내에 전역 <literal>SessionFactory</literal>를 산출할 뿐만 아니라 또한 현""재 쓰레드에 대한 <literal>Session</literal>을 소유하는 <literal>ThreadLocal</""literal> 변수를 갖는다. 당신이 <literal>HibernateUtil.getCurrentSession()</""literal>을 호출하는 시점에는 문제가 없으며, 그것은 항상 동일 쓰레드 내에 동일""한 Hibernate 작업 단위를 반환할 것이다. <literal>HibernateUtil.closeSession()""</literal>에 대한 호출은 쓰레드와 현재 연관되어 있는 작업 단위를 종료시킨다."#. Tag: para#: tutorial.xml:361#, no-c-formatmsgid """If you give the <literal>SessionFactory</literal> a name in your ""configuration file, Hibernate will in fact try to bind it to JNDI after it ""has been built. To avoid this code completely you could also use JMX ""deployment and let the JMX-capable container instantiate and bind a ""<literal>HibernateService</literal> to JNDI. These advanced options are ""discussed in the Hibernate reference documentation."msgstr """당신이 이 helper를 사용하기 전에 thread-local 변수들에 대한 Java 개념을 확실""히 이해하도록 하라. 보다 강력한 <literal>HibernateUtil</literal> helper는 ""http://caveatemptor.hibernate.org/에 있는 <literal>CaveatEmptor</literal> 뿐""만 아니라 \"Java Persistence with Hibernate\" 책에서 찾을 수 있다. 당신이 ""J2EE 어플리케이션 서버 내에 Hibernate를 배치할 경우에 이 클래스는 필수적이지 ""않다: 하나의 <literal>Session</literal>은 현재의 JTA 트랜잭션에 자동적으로 바""인드 될 것이고 당신은 JNDI를 통해 <literal>SessionFactory</literal>를 룩업할 ""수 있다. 만일 당신이 JBoss AS를 사용할 경우, Hibernate는 관리되는 시스템 서비""스로서 배치될 수 있고 <literal>SessionFactory</literal>를 JNDI 이름에 자동적""으로 바인드시킬 수 있을 것이다."#. Tag: para#: tutorial.xml:370#, no-c-formatmsgid """Place <literal>HibernateUtil.java</literal> in the development source ""directory, in a package next to <literal>events</literal>:"msgstr """개발 소스 디렉토리 속에 <literal>HibernateUtil.java</literal> 를 위치지우고, ""다음으로 <literal>Event.java</literal>를 위치지워라:"#. Tag: programlisting#: tutorial.xml:375#, no-c-formatmsgid """<![CDATA[.\n""+lib\n"" <Hibernate and third-party libraries>\n""+src\n"" +events\n"" Event.java\n"" Event.hbm.xml\n"" +util\n"" HibernateUtil.java\n"" hibernate.cfg.xml\n""+data\n""build.xml]]>"msgstr ""#. Tag: para#: tutorial.xml:377#, no-c-formatmsgid """This should again compile without problems. We finally need to configure a ""logging system - Hibernate uses commons logging and leaves you the choice ""between Log4j and JDK 1.4 logging. Most developers prefer Log4j: copy ""<literal>log4j.properties</literal> from the Hibernate distribution (it's in ""the <literal>etc/</literal> directory) to your <literal>src</literal> ""directory, next to <literal>hibernate.cfg.xml</literal>. Have a look at the ""example configuration and change the settings if you like to have more ""verbose output. By default, only Hibernate startup message are shown on ""stdout."msgstr """이것은 문제 없이 다시 컴파일 될 것이다. 우리는 마지막으로 로깅 시스템을 구성""할 필요가 있다 - Hibernate는 commons logging를 사용하고 Log4j와 JDK 1.4 사이""의 선택은 당신의 몫으로 남겨둔다. 대부분의 개발자들은 Log4j를 선호한다: ""Hibernate 배포본에 있는 <literal>log4j.properties</literal>(이것은 디렉토리 ""<literal>etc/</literal> 내에 있다)를 <literal>src</literal> 디렉토리로 복사하""고, 다음으로 <literal>hibernate.cfg.xml</literal>을 복사하라. 예제 구성을 살""펴보고 당신이 더 많은 verbose 출력을 원할 경우에 설정들을 변경하라. 디폴트로 ""Hibernate 시작 메시지는 stdout 상에 보여진다."#. Tag: para#: tutorial.xml:387#, no-c-formatmsgid """The tutorial infrastructure is complete - and we are ready to do some real ""work with Hibernate."msgstr """튜토리얼 인프라스트럭처는 완전하다 - 그리고 우리는 Hibernate로 어떤 실제 작업""을 행할 준비가 되어 있다."#. Tag: title#: tutorial.xml:395#, no-c-formatmsgid "Loading and storing objects"msgstr "객체 로딩과 객체 저장"#. Tag: para#: tutorial.xml:397#, no-c-formatmsgid """Finally, we can use Hibernate to load and store objects. We write an ""<literal>EventManager</literal> class with a <literal>main()</literal> ""method:"msgstr """마지막으로 우리는 객체들을 로드시키고 저장하는데 Hibernate를 사용할 수 있다. ""우리는 한 개의 <literal>main()</literal> 메소드를 가진 한 개의 ""<literal>EventManager</literal> 클래스를 작성한다:"#. Tag: programlisting#: tutorial.xml:402#, no-c-formatmsgid """<![CDATA[package events;\n""import org.hibernate.Session;\n""\n""import java.util.Date;\n""\n""import util.HibernateUtil;\n""\n""public class EventManager {\n""\n"" public static void main(String[] args) {\n"" EventManager mgr = new EventManager();\n""\n"" if (args[0].equals(\"store\")) {\n"" mgr.createAndStoreEvent(\"My Event\", new Date());\n"" }\n""\n"" HibernateUtil.getSessionFactory().close();\n"" }\n""\n"" private void createAndStoreEvent(String title, Date theDate) {\n""\n"" Session session = HibernateUtil.getSessionFactory().getCurrentSession""();\n""\n"" session.beginTransaction();\n""\n"" Event theEvent = new Event();\n"" theEvent.setTitle(title);\n"" theEvent.setDate(theDate);\n""\n"" session.save(theEvent);\n""\n"" session.getTransaction().commit();\n"" }\n""\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:404#, no-c-formatmsgid """We create a new <literal>Event</literal> object, and hand it over to ""Hibernate. Hibernate now takes care of the SQL and executes <literal>INSERT</""literal>s on the database. Let's have a look at the <literal>Session</""literal> and <literal>Transaction</literal>-handling code before we run this."msgstr """우리는 한 개의 새로운 <literal>Event</literal> 객체를 생성시키고, 그것을 ""Hibernate에게 건네준다. Hibernate는 이제 SQL을 처리하고 데이터베이스 상에서 ""<literal>INSERT</literal>들을 실행시킨다. -우리가 이것을 실행하기 전에 코드""를 처리하는- <literal>Session</literal>과 <literal>Transaction</literal>을 살""펴보자."#. Tag: para#: tutorial.xml:411#, no-c-formatmsgid """A <literal>Session</literal> is a single unit of work. For now we'll keep ""things simple and assume a one-to-one granularity between a Hibernate ""<literal>Session</literal> and a database transaction. To shield our code ""from the actual underlying transaction system (in this case plain JDBC, but ""it could also run with JTA) we use the <literal>Transaction</literal> API ""that is available on the Hibernate <literal>Session</literal>."msgstr """<literal>Session</literal>은 한 개의 작업 단위이다. 지금부터 우리는 단숨함을 ""유지할 것이고 Hibernate <literal>Session</literal>과 데이터베이스 트랜잭션 사""이의 일-대-일 과립형(granularity)을 가정할 것이다. 실제 기반 트랜잭션 시스템""으로부터 우리의 소스를 은폐시키기 위해(이 경우 통상의 JDBC이지만, 그것은 또""한 JTA에도 실행된다) 우리는 Hibernate <literal>Session</literal> 상에서 이용 ""가능한 <literal>Transaction</literal> API를 사용한다."#. Tag: para#: tutorial.xml:419#, no-c-formatmsgid """What does <literal>sessionFactory.getCurrentSession()</literal> do? First, ""you can call it as many times and anywhere you like, once you get hold of ""your <literal>SessionFactory</literal> (easy thanks to ""<literal>HibernateUtil</literal>). The <literal>getCurrentSession()</""literal> method always returns the \"current\" unit of work. Remember that ""we switched the configuration option for this mechanism to \"thread\" in ""<literal>hibernate.cfg.xml</literal>? Hence, the current unit of work is ""bound to the current Java thread that executes our application. However, ""this is not the full picture, you also have to consider scope, when a unit ""of work begins and when it ends."msgstr """<literal>sessionFactory.getCurrentSession()</literal>은 무엇을 행하는가? 먼""저 당신은 당신이 (<literal>HibernateUtil</literal> 덕분에 쉽게) ""<literal>SessionFactory</literal>을 당신이 소유하고 있다면, 원하는 만큼 어디""서든 여러번 그것을 호출할 수 있다. <literal>getCurrentSession()</literal> 메""소드는 항상 \"현재의\" 작업 단위를 반환한다. 우리가 <literal>hibernate.cfg.""xml</literal> 내에서 이 매커니즘에 대한 구성 옵션을 \"thread\"로 전환시켰음""을 기억하는가? 그러므로 작업의 현재 단위는 우리의 어플리케이션을 실행시키는 ""현재 자바 쓰레드에 묶여 있다. 하지만 이것은 전체 그림이 아니며, 당신은 또한 ""scope(영역), 작업 단위가 시작될 때와 작업 단위가 종료될 때를 고려해야 한다."#. Tag: para#: tutorial.xml:430#, no-c-formatmsgid """A <literal>Session</literal> begins when it is first needed, when the first ""call to <literal>getCurrentSession()</literal> is made. It is then bound by ""Hibernate to the current thread. When the transaction ends, either through ""commit or rollback, Hibernate automatically unbinds the <literal>Session</""literal> from the thread and closes it for you. If you call ""<literal>getCurrentSession()</literal> again, you get a new ""<literal>Session</literal> and can start a new unit of work. This ""<emphasis>thread-bound</emphasis> programming model is the most popular way ""of using Hibernate, as it allows flexible layering of your code (transaction ""demarcation code can be separated from data access code, we'll do this later ""in this tutorial)."msgstr """<literal>Session</literal>은 그것이 처음으로 필요로 되고 ""<literal>getCurrentSession()</literal>에 대한 첫 번째 호출이 이루어질 때 시작""된다. 그때 그것은 Hibernate에 의해 현재의 쓰레드에 바인드 된다. 커밋되든 롤백""되든 간에 트랜잭션이 종료되고, Hibernate가 자동적으로 그 쓰레드로부터 ""<literal>Session</literal>을 바인드 해제시키고 당신을 위해 세션을 닫는다. 만"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -