⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 5 页
字号:
#, no-c-formatmsgid """This is the <literal>INSERT</literal> executed by Hibernate, the question ""marks represent JDBC bind parameters. To see the values bound as arguments, ""or to reduce the verbosity of the log, check your <literal>log4j.properties</""literal>."msgstr """Este é o <literal>INSERT</literal> executado pelo Hibernate, os pontos de ""interrogação representam parêmetros de união do JDBC. Para ver os valores ""substituídos, ou para diminuir a verbalidade do log, check seu ""l<literal>log4j.properties</literal>."#. Tag: para#: tutorial.xml:484#, no-c-formatmsgid """Now we'd like to list stored events as well, so we add an option to the main ""method:"msgstr """Agora nós gostaríamos de listar os eventos arquivados, então nós adicionamos ""uma opção para o método main:"#. Tag: programlisting#: tutorial.xml:488#, no-c-formatmsgid """<![CDATA[if (args[0].equals(\"store\")) {\n""    mgr.createAndStoreEvent(\"My Event\", new Date());\n""}\n""else if (args[0].equals(\"list\")) {\n""    List events = mgr.listEvents();\n""    for (int i = 0; i < events.size(); i++) {\n""        Event theEvent = (Event) events.get(i);\n""        System.out.println(\"Event: \" + theEvent.getTitle() +\n""                           \" Time: \" + theEvent.getDate());\n""    }\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:490#, no-c-formatmsgid "We also add a new <literal>listEvents() method</literal>:"msgstr "Nos também adicionamos um novo <literal>método listEvents()</literal>:"#. Tag: programlisting#: tutorial.xml:494#, no-c-formatmsgid """<![CDATA[private List listEvents() {\n""\n""    Session session = HibernateUtil.getSessionFactory().getCurrentSession""();\n""\n""    session.beginTransaction();\n""\n""    List result = session.createQuery(\"from Event\").list();\n""\n""    session.getTransaction().commit();\n""\n""    return result;\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:496#, no-c-formatmsgid """What we do here is use an HQL (Hibernate Query Language) query to load all ""existing <literal>Event</literal> objects from the database. Hibernate will ""generate the appropriate SQL, send it to the database and populate ""<literal>Event</literal> objects with the data. You can create more complex ""queries with HQL, of course."msgstr """O que nós fazemos aqui, é usar uma query HQL (Hibernate Query Language), ""para carregar todos os objetos <literal>Event</literal> exitentes no banco ""de dados. O Hibernate irá gerar o SQL apropriado, enviar para o banco de ""dados e popular objetos <literal>Event</literal> com os dados. Você pode ""criar queries mais complexas com HQL, claro."#. Tag: para#: tutorial.xml:503#, no-c-formatmsgid "Now, to execute and test all of this, follow these steps:"msgstr "Agora, para executar e testar tudo isso, siga os passos a seguir:"#. Tag: para#: tutorial.xml:509#, no-c-formatmsgid """Run <literal>ant run -Daction=store</literal> to store something into the ""database and, of course, to generate the database schema before through ""hbm2ddl."msgstr """Execute <literal>ant run -Daction=store</literal> para armazenar algo no ""banco de dados e, claro, gerar o esquema do banco de dados antes pelo ""hbm2ddl."#. Tag: para#: tutorial.xml:515#, no-c-formatmsgid """Now disable hbm2ddl by commenting out the property in your ""<literal>hibernate.cfg.xml</literal> file. Usually you only leave it turned ""on in continous unit testing, but another run of hbm2ddl would ""<emphasis>drop</emphasis> everything you have stored - the <literal>create</""literal> configuration setting actually translates into \"drop all tables ""from the schema, then re-create all tables, when the SessionFactory is build""\"."msgstr """Agora desabilite hbm2ddl comentando a propriedade no seu arquivo ""<literal>hibernate.cfg.xml</literal>. Normalmente só se deixa habilitado em ""teste unitários contínuos, mas outra carga de hbm2ddl pode ""<emphasis>remover</emphasis> tudo que você já tenha arquivado. Sa ""configuração <literal>create</literal>, atualmente são traduzidas para ""\"apague todas as tabelas do esquema, então recrie todas quando a ""SessionFactory estiver pronta\"."#. Tag: para#: tutorial.xml:525#, no-c-formatmsgid """If you now call Ant with <literal>-Daction=list</literal>, you should see ""the events you have stored so far. You can of course also call the ""<literal>store</literal> action a few times more."msgstr """Se você agora chamar o Ant com <literal>-Daction=list</literal>, você deverá ""ver os eventos que você acabou de criar. Você pode também chamar a ação ""<literal>store</literal> mais algumas vezes."#. Tag: para#: tutorial.xml:531#, no-c-formatmsgid """Note: Most new Hibernate users fail at this point and we see questions about ""<emphasis>Table not found</emphasis> error messages regularly. However, if ""you follow the steps outlined above you will not have this problem, as ""hbm2ddl creates the database schema on the first run, and subsequent ""application restarts will use this schema. If you change the mapping and/or ""database schema, you have to re-enable hbm2ddl once again."msgstr """Nota: A maioria dos novos usuários do Hibernate falha nesse ponto e nós ""regularmente, vemos questões sobre mensagens de erro de <emphasis>tabela não ""encontrada </emphasis> . Entretanto, se você seguir os passos marcados ""acima, você não terá esse problema, com o hbm2ddl criando o esquema do banco ""de dados na primeira execução, e restarts subsequentes da aplicação irão ""usar este esquema. Se você mudar o mapeamento e/ou o esquema do banco de ""dados, terá de re-habilitar o hbm2ddl mais uma vez."#. Tag: title#: tutorial.xml:544#, no-c-formatmsgid "Part 2 - Mapping associations"msgstr "Part 2 - Mapeando associações"#. Tag: para#: tutorial.xml:546#, no-c-formatmsgid """We mapped a persistent entity class to a table. Let's build on this and add ""some class associations. First we'll add people to our application, and ""store a list of events they participate in."msgstr """Nós mapeamos uma classe de entidade de persistência para uma tabela. Agora ""vamos continuar e adicionar algumas associações de classe. Primeiro nos ""iremos adicionar pessoas a nossa aplicação, e armazenar os eventos de que ""elas participam."#. Tag: title#: tutorial.xml:552#, no-c-formatmsgid "Mapping the Person class"msgstr "Mapeando a classe Person"#. Tag: para#: tutorial.xml:554#, no-c-formatmsgid "The first cut of the <literal>Person</literal> class is simple:"msgstr "O primeiro código da classe <literal>Person</literal> é simples:"#. Tag: programlisting#: tutorial.xml:558#, no-c-formatmsgid """<![CDATA[package events;\n""\n""public class Person {\n""\n""    private Long id;\n""    private int age;\n""    private String firstname;\n""    private String lastname;\n""\n""    public Person() {}\n""\n""    // Accessor methods for all properties, private setter for 'id'\n""\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:560#, no-c-formatmsgid """Create a new mapping file called <literal>Person.hbm.xml</literal> (don't ""forget the DTD reference at the top):"msgstr """Crie um novo arquivo de mapeamento, chamado <literal>Person.hbm.xml</""literal> (não esqueça a referencia ao DTD no topo)"#. Tag: programlisting#: tutorial.xml:565#, no-c-formatmsgid """<![CDATA[<hibernate-mapping>\n""\n""    <class name=\"events.Person\" table=\"PERSON\">\n""        <id name=\"id\" column=\"PERSON_ID\">\n""            <generator class=\"native\"/>\n""        </id>\n""        <property name=\"age\"/>\n""        <property name=\"firstname\"/>\n""        <property name=\"lastname\"/>\n""    </class>\n""\n""</hibernate-mapping>]]>"msgstr ""#. Tag: para#: tutorial.xml:567#, no-c-formatmsgid "Finally, add the new mapping to Hibernate's configuration:"msgstr "Finalmente, adicione o novo mapeamento a configuração do Hibernate:"#. Tag: programlisting#: tutorial.xml:571#, no-c-formatmsgid """<![CDATA[<mapping resource=\"events/Event.hbm.xml\"/>\n""<mapping resource=\"events/Person.hbm.xml\"/>]]>"msgstr ""#. Tag: para#: tutorial.xml:573#, no-c-formatmsgid """We'll now create an association between these two entities. Obviously, ""persons can participate in events, and events have participants. The design ""questions we have to deal with are: directionality, multiplicity, and ""collection behavior."msgstr """Nos iremos agora criar uma associação entre estas duas entidades. ""Obviamente, pessoas (Person) podem participar de eventos, e eventos possuem ""participantes. As questões de design com que teremos de lidar são: ""direcionalidade, multiplicidade e comportamento de coleção."#. Tag: title#: tutorial.xml:583#, no-c-formatmsgid "A unidirectional Set-based association"msgstr "Uma associação Set-based unidirectional"#. Tag: para#: tutorial.xml:585#, no-c-formatmsgid """We'll add a collection of events to the <literal>Person</literal> class. ""That way we can easily navigate to the events for a particular person, ""without executing an explicit query - by calling <literal>aPerson.getEvents()""</literal>. We use a Java collection, a <literal>Set</literal>, because the ""collection will not contain duplicate elements and the ordering is not ""relevant for us."msgstr """Nos iremos adicionar uma coleção de eventos na classe <literal>Person</""literal>. Desse jeito poderemos navegar pelos eventos de uma pessoa em ""particular, sem executar uma query explicitamente – apenas chamando ""<literal>aPerson.getEvents()</literal>. Nos usaremos uma coleção Java, um ""<literal>Set</literal>, porquê a coleção não conterá elementos duplicados e ""a ordem não é relevante para nós."#. Tag: para#: tutorial.xml:592#, no-c-formatmsgid """We need a unidirectional, many-valued associations, implemented with a ""<literal>Set</literal>. Let's write the code for this in the Java classes ""and then map it:"msgstr "Vamos escrever o código para isto nas classes Java e então mapear:"#. Tag: programlisting#: tutorial.xml:597#, no-c-formatmsgid """<![CDATA[public class Person {\n""\n""    private Set events = new HashSet();\n""\n""    public Set getEvents() {\n""        return events;\n""    }\n""\n""    public void setEvents(Set events) {\n""        this.events = events;\n""    }\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:599#, no-c-formatmsgid """Before we map this association, think about the other side. Clearly, we ""could just keep this unidirectional. Or, we could create another collection ""on the <literal>Event</literal>, if we want to be able to navigate it bi-""directional, i.e. <literal>anEvent.getParticipants()</literal>. This is not ""necessary, from a functional perspective. You could always execute an ""explicit query to retrieve the participants for a particular event. This is ""a design choice left to you, but what is clear from this discussion is the ""multiplicity of the association: \"many\" valued on both sides, we call this ""a <emphasis>many-to-many</emphasis> association. Hence, we use Hibernate's ""many-to-many mapping:"msgstr """Antes de mapearmos esta associação, pense no outro lado. Claramente, ""poderíamos apenas fazer isto de forma unidirecional. Ou poderíamos criar ""outra coleção no <literal>Event</literal>, se quisermos ser capaz de navegar ""bidirecionalmente, i.e. um - <literal>anEvent.getParticipants()</literal>. ""Isto não é necessário, de perspectiva funcional. Você poderia sempre ""executar uma query explicita que retornasse os participantes de um evento em ""particular. Esta

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -