|
Hibernate example source code file (example_weblog.po)
The Hibernate example_weblog.po source code# translation of Collection_Mapping.po to # Xi Huang <xhuang@redhat.com>, 2006. # Xi HUANG <xhuang@redhat.com>, 2007. msgid "" msgstr "" "Project-Id-Version: Collection_Mapping\n" "Report-Msgid-Bugs-To: http://bugs.kde.org\n" "POT-Creation-Date: 2010-02-10T07:25:35\n" "PO-Revision-Date: 2009-11-27 13:54+1000\n" "Last-Translator: Xi HUANG <xhuang@redhat.com>\n" "Language-Team: <en@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: KBabel 1.11.4\n" #. Tag: title #, no-c-format msgid "Example: Weblog Application" msgstr "示例:Weblog 应用程序 " #. Tag: title #, no-c-format msgid "Persistent Classes" msgstr "持久化类(Persistent Classes)" #. Tag: para #, no-c-format msgid "" "The persistent classes here represent a weblog and an item posted in a " "weblog. They are to be modelled as a standard parent/child relationship, but " "we will use an ordered bag, instead of a set:" msgstr "" "下面的持久化类表示一个 weblog 和在其中张贴的一个贴子。他们是标准的父/子关系模" "型,但是我们会用一个有序包(ordered bag)而非集合(set)。 " #. Tag: title #, no-c-format msgid "Hibernate Mappings" msgstr "Hibernate 映射" #. Tag: para #, no-c-format msgid "The XML mappings are now straightforward. For example:" msgstr "下列的 XML 映射应该是很直白的。例如:" #. Tag: title #, no-c-format msgid "Hibernate Code" msgstr "Hibernate 代码" #. Tag: para #, no-c-format msgid "" "The following class demonstrates some of the kinds of things we can do with " "these classes using Hibernate:" msgstr "下面的类演示了我们可以使用 Hibernate 对这些类进行的一些操作:" #~ msgid "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.util.List;\n" #~ "\n" #~ "public class Blog {\n" #~ " private Long _id;\n" #~ " private String _name;\n" #~ " private List _items;\n" #~ "\n" #~ " public Long getId() {\n" #~ " return _id;\n" #~ " }\n" #~ " public List getItems() {\n" #~ " return _items;\n" #~ " }\n" #~ " public String getName() {\n" #~ " return _name;\n" #~ " }\n" #~ " public void setId(Long long1) {\n" #~ " _id = long1;\n" #~ " }\n" #~ " public void setItems(List list) {\n" #~ " _items = list;\n" #~ " }\n" #~ " public void setName(String string) {\n" #~ " _name = string;\n" #~ " }\n" #~ "}]]>" #~ msgstr "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.util.List;\n" #~ "\n" #~ "public class Blog {\n" #~ " private Long _id;\n" #~ " private String _name;\n" #~ " private List _items;\n" #~ "\n" #~ " public Long getId() {\n" #~ " return _id;\n" #~ " }\n" #~ " public List getItems() {\n" #~ " return _items;\n" #~ " }\n" #~ " public String getName() {\n" #~ " return _name;\n" #~ " }\n" #~ " public void setId(Long long1) {\n" #~ " _id = long1;\n" #~ " }\n" #~ " public void setItems(List list) {\n" #~ " _items = list;\n" #~ " }\n" #~ " public void setName(String string) {\n" #~ " _name = string;\n" #~ " }\n" #~ "}]]>" #~ msgid "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.text.DateFormat;\n" #~ "import java.util.Calendar;\n" #~ "\n" #~ "public class BlogItem {\n" #~ " private Long _id;\n" #~ " private Calendar _datetime;\n" #~ " private String _text;\n" #~ " private String _title;\n" #~ " private Blog _blog;\n" #~ "\n" #~ " public Blog getBlog() {\n" #~ " return _blog;\n" #~ " }\n" #~ " public Calendar getDatetime() {\n" #~ " return _datetime;\n" #~ " }\n" #~ " public Long getId() {\n" #~ " return _id;\n" #~ " }\n" #~ " public String getText() {\n" #~ " return _text;\n" #~ " }\n" #~ " public String getTitle() {\n" #~ " return _title;\n" #~ " }\n" #~ " public void setBlog(Blog blog) {\n" #~ " _blog = blog;\n" #~ " }\n" #~ " public void setDatetime(Calendar calendar) {\n" #~ " _datetime = calendar;\n" #~ " }\n" #~ " public void setId(Long long1) {\n" #~ " _id = long1;\n" #~ " }\n" #~ " public void setText(String string) {\n" #~ " _text = string;\n" #~ " }\n" #~ " public void setTitle(String string) {\n" #~ " _title = string;\n" #~ " }\n" #~ "}]]>" #~ msgstr "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.text.DateFormat;\n" #~ "import java.util.Calendar;\n" #~ "\n" #~ "public class BlogItem {\n" #~ " private Long _id;\n" #~ " private Calendar _datetime;\n" #~ " private String _text;\n" #~ " private String _title;\n" #~ " private Blog _blog;\n" #~ "\n" #~ " public Blog getBlog() {\n" #~ " return _blog;\n" #~ " }\n" #~ " public Calendar getDatetime() {\n" #~ " return _datetime;\n" #~ " }\n" #~ " public Long getId() {\n" #~ " return _id;\n" #~ " }\n" #~ " public String getText() {\n" #~ " return _text;\n" #~ " }\n" #~ " public String getTitle() {\n" #~ " return _title;\n" #~ " }\n" #~ " public void setBlog(Blog blog) {\n" #~ " _blog = blog;\n" #~ " }\n" #~ " public void setDatetime(Calendar calendar) {\n" #~ " _datetime = calendar;\n" #~ " }\n" #~ " public void setId(Long long1) {\n" #~ " _id = long1;\n" #~ " }\n" #~ " public void setText(String string) {\n" #~ " _text = string;\n" #~ " }\n" #~ " public void setTitle(String string) {\n" #~ " _title = string;\n" #~ " }\n" #~ "}]]>" #~ msgid "" #~ "<![CDATA[" #~ msgstr "" #~ "<![CDATA[" #~ msgid "" #~ "<![CDATA[" #~ msgstr "" #~ "<![CDATA[" #~ msgid "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.util.ArrayList;\n" #~ "import java.util.Calendar;\n" #~ "import java.util.Iterator;\n" #~ "import java.util.List;\n" #~ "\n" #~ "import org.hibernate.HibernateException;\n" #~ "import org.hibernate.Query;\n" #~ "import org.hibernate.Session;\n" #~ "import org.hibernate.SessionFactory;\n" #~ "import org.hibernate.Transaction;\n" #~ "import org.hibernate.cfg.Configuration;\n" #~ "import org.hibernate.tool.hbm2ddl.SchemaExport;\n" #~ "\n" #~ "public class BlogMain {\n" #~ " \n" #~ " private SessionFactory _sessions;\n" #~ " \n" #~ " public void configure() throws HibernateException {\n" #~ " _sessions = new Configuration()\n" #~ " .addClass(Blog.class)\n" #~ " .addClass(BlogItem.class)\n" #~ " .buildSessionFactory();\n" #~ " }\n" #~ " \n" #~ " public void exportTables() throws HibernateException {\n" #~ " Configuration cfg = new Configuration()\n" #~ " .addClass(Blog.class)\n" #~ " .addClass(BlogItem.class);\n" #~ " new SchemaExport(cfg).create(true, true);\n" #~ " }\n" #~ " \n" #~ " public Blog createBlog(String name) throws HibernateException {\n" #~ " \n" #~ " Blog blog = new Blog();\n" #~ " blog.setName(name);\n" #~ " blog.setItems( new ArrayList() );\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.persist(blog);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return blog;\n" #~ " }\n" #~ " \n" #~ " public BlogItem createBlogItem(Blog blog, String title, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " BlogItem item = new BlogItem();\n" #~ " item.setTitle(title);\n" #~ " item.setText(text);\n" #~ " item.setBlog(blog);\n" #~ " item.setDatetime( Calendar.getInstance() );\n" #~ " blog.getItems().add(item);\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.update(blog);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return item;\n" #~ " }\n" #~ " \n" #~ " public BlogItem createBlogItem(Long blogid, String title, String " #~ "text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " BlogItem item = new BlogItem();\n" #~ " item.setTitle(title);\n" #~ " item.setText(text);\n" #~ " item.setDatetime( Calendar.getInstance() );\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Blog blog = (Blog) session.load(Blog.class, blogid);\n" #~ " item.setBlog(blog);\n" #~ " blog.getItems().add(item);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return item;\n" #~ " }\n" #~ " \n" #~ " public void updateBlogItem(BlogItem item, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " item.setText(text);\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.update(item);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " }\n" #~ " \n" #~ " public void updateBlogItem(Long itemid, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " BlogItem item = (BlogItem) session.load(BlogItem.class, " #~ "itemid);\n" #~ " item.setText(text);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " }\n" #~ " \n" #~ " public List listAllBlogNamesAndItemCounts(int max)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " List result = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"select blog.id, blog.name, count(blogItem) \" +\n" #~ " \"from Blog as blog \" +\n" #~ " \"left outer join blog.items as blogItem \" +\n" #~ " \"group by blog.name, blog.id \" +\n" #~ " \"order by max(blogItem.datetime)\"\n" #~ " );\n" #~ " q.setMaxResults(max);\n" #~ " result = q.list();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return result;\n" #~ " }\n" #~ " \n" #~ " public Blog getBlogAndAllItems(Long blogid)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " Blog blog = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"from Blog as blog \" +\n" #~ " \"left outer join fetch blog.items \" +\n" #~ " \"where blog.id = :blogid\"\n" #~ " );\n" #~ " q.setParameter(\"blogid\", blogid);\n" #~ " blog = (Blog) q.uniqueResult();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return blog;\n" #~ " }\n" #~ " \n" #~ " public List listBlogsAndRecentItems() throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " List result = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"from Blog as blog \" +\n" #~ " \"inner join blog.items as blogItem \" +\n" #~ " \"where blogItem.datetime > :minDate\"\n" #~ " );\n" #~ "\n" #~ " Calendar cal = Calendar.getInstance();\n" #~ " cal.roll(Calendar.MONTH, false);\n" #~ " q.setCalendar(\"minDate\", cal);\n" #~ " \n" #~ " result = q.list();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return result;\n" #~ " }\n" #~ "}]]>" #~ msgstr "" #~ "<![CDATA[package eg;\n" #~ "\n" #~ "import java.util.ArrayList;\n" #~ "import java.util.Calendar;\n" #~ "import java.util.Iterator;\n" #~ "import java.util.List;\n" #~ "\n" #~ "import org.hibernate.HibernateException;\n" #~ "import org.hibernate.Query;\n" #~ "import org.hibernate.Session;\n" #~ "import org.hibernate.SessionFactory;\n" #~ "import org.hibernate.Transaction;\n" #~ "import org.hibernate.cfg.Configuration;\n" #~ "import org.hibernate.tool.hbm2ddl.SchemaExport;\n" #~ "\n" #~ "public class BlogMain {\n" #~ " \n" #~ " private SessionFactory _sessions;\n" #~ " \n" #~ " public void configure() throws HibernateException {\n" #~ " _sessions = new Configuration()\n" #~ " .addClass(Blog.class)\n" #~ " .addClass(BlogItem.class)\n" #~ " .buildSessionFactory();\n" #~ " }\n" #~ " \n" #~ " public void exportTables() throws HibernateException {\n" #~ " Configuration cfg = new Configuration()\n" #~ " .addClass(Blog.class)\n" #~ " .addClass(BlogItem.class);\n" #~ " new SchemaExport(cfg).create(true, true);\n" #~ " }\n" #~ " \n" #~ " public Blog createBlog(String name) throws HibernateException {\n" #~ " \n" #~ " Blog blog = new Blog();\n" #~ " blog.setName(name);\n" #~ " blog.setItems( new ArrayList() );\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.persist(blog);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return blog;\n" #~ " }\n" #~ " \n" #~ " public BlogItem createBlogItem(Blog blog, String title, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " BlogItem item = new BlogItem();\n" #~ " item.setTitle(title);\n" #~ " item.setText(text);\n" #~ " item.setBlog(blog);\n" #~ " item.setDatetime( Calendar.getInstance() );\n" #~ " blog.getItems().add(item);\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.update(blog);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return item;\n" #~ " }\n" #~ " \n" #~ " public BlogItem createBlogItem(Long blogid, String title, String " #~ "text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " BlogItem item = new BlogItem();\n" #~ " item.setTitle(title);\n" #~ " item.setText(text);\n" #~ " item.setDatetime( Calendar.getInstance() );\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Blog blog = (Blog) session.load(Blog.class, blogid);\n" #~ " item.setBlog(blog);\n" #~ " blog.getItems().add(item);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return item;\n" #~ " }\n" #~ " \n" #~ " public void updateBlogItem(BlogItem item, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " item.setText(text);\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " session.update(item);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " }\n" #~ " \n" #~ " public void updateBlogItem(Long itemid, String text)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " BlogItem item = (BlogItem) session.load(BlogItem.class, " #~ "itemid);\n" #~ " item.setText(text);\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " }\n" #~ " \n" #~ " public List listAllBlogNamesAndItemCounts(int max)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " List result = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"select blog.id, blog.name, count(blogItem) \" +\n" #~ " \"from Blog as blog \" +\n" #~ " \"left outer join blog.items as blogItem \" +\n" #~ " \"group by blog.name, blog.id \" +\n" #~ " \"order by max(blogItem.datetime)\"\n" #~ " );\n" #~ " q.setMaxResults(max);\n" #~ " result = q.list();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return result;\n" #~ " }\n" #~ " \n" #~ " public Blog getBlogAndAllItems(Long blogid)\n" #~ " throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " Blog blog = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"from Blog as blog \" +\n" #~ " \"left outer join fetch blog.items \" +\n" #~ " \"where blog.id = :blogid\"\n" #~ " );\n" #~ " q.setParameter(\"blogid\", blogid);\n" #~ " blog = (Blog) q.uniqueResult();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return blog;\n" #~ " }\n" #~ " \n" #~ " public List listBlogsAndRecentItems() throws HibernateException {\n" #~ " \n" #~ " Session session = _sessions.openSession();\n" #~ " Transaction tx = null;\n" #~ " List result = null;\n" #~ " try {\n" #~ " tx = session.beginTransaction();\n" #~ " Query q = session.createQuery(\n" #~ " \"from Blog as blog \" +\n" #~ " \"inner join blog.items as blogItem \" +\n" #~ " \"where blogItem.datetime > :minDate\"\n" #~ " );\n" #~ "\n" #~ " Calendar cal = Calendar.getInstance();\n" #~ " cal.roll(Calendar.MONTH, false);\n" #~ " q.setCalendar(\"minDate\", cal);\n" #~ " \n" #~ " result = q.list();\n" #~ " tx.commit();\n" #~ " }\n" #~ " catch (HibernateException he) {\n" #~ " if (tx!=null) tx.rollback();\n" #~ " throw he;\n" #~ " }\n" #~ " finally {\n" #~ " session.close();\n" #~ " }\n" #~ " return result;\n" #~ " }\n" #~ "}]]>" Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate example_weblog.po source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.