|
Hibernate example source code file (example_weblog.po)
The Hibernate example_weblog.po source code# translation of Collection_Mapping.po to # translation of Collection_Mapping.po to # translation of Collection_Mapping.po to # translation of Collection_Mapping.po to # translation of Collection_Mapping.po to # translation of Collection_Mapping.po to # Language /mnt/hgfs/base/Hibernate/Reference translations for PACKAGE package. # Copyright (C) 2006, 2007 Free Software Foundation, Inc. # Automatically generated, 2006. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 2007. # , 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: 2007-02-26 10:27+1000\n" "Last-Translator: \n" "Language-Team: <de@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.9.1\n" #. Tag: title #, no-c-format msgid "Example: Weblog Application" msgstr "Beispiel: Web-Log Anwendung" #. Tag: title #, no-c-format msgid "Persistent Classes" msgstr "Persistente Klassen" #. Tag: para #, fuzzy, 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 "" "Die persistenten Klassen repräsentieren einen Web-Log und einen in einem Web-" "Log untergebrachten Posten. Sie sollen als Standard \"Parent/Child\"-" "Beziehung modelliert werden, jedoch verwenden wir eine geordnete \"Bag\" " "anstelle eines \"Sets\"." #. Tag: title #, no-c-format msgid "Hibernate Mappings" msgstr "Hibernate-Mappings" #. Tag: para #, fuzzy, no-c-format msgid "The XML mappings are now straightforward. For example:" msgstr "Die XML-Mappings sollten nun ziemlich überschaubar sein." #. Tag: title #, no-c-format msgid "Hibernate Code" msgstr "Hibernate-Code" #. Tag: para #, fuzzy, no-c-format msgid "" "The following class demonstrates some of the kinds of things we can do with " "these classes using Hibernate:" msgstr "" "Die folgende Klasse zeigt einige Dinge auf, die unter Verwendung von " "Hibernate mit diesen Klassen durchgeführt werden können." #, fuzzy #~ 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 "" #~ "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" #~ "}" #, fuzzy #~ 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 "" #~ "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" #~ "}" #, fuzzy #~ msgid "" #~ "<![CDATA[" #~ msgstr "" #~ "<?xml version=\"1.0\"?>\n" #~ "<!DOCTYPE hibernate-mapping PUBLIC\n" #~ " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" #~ " \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n" #~ "\n" #~ "<hibernate-mapping package=\"eg\">\n" #~ "\n" #~ " <class\n" #~ " name=\"Blog\"\n" #~ " table=\"BLOGS\">\n" #~ "\n" #~ " <id\n" #~ " name=\"id\"\n" #~ " column=\"BLOG_ID\">\n" #~ "\n" #~ " <generator class=\"native\"/>\n" #~ "\n" #~ " </id>\n" #~ "\n" #~ " <property\n" #~ " name=\"name\"\n" #~ " column=\"NAME\"\n" #~ " not-null=\"true\"\n" #~ " unique=\"true\"/>\n" #~ "\n" #~ " <bag\n" #~ " name=\"items\"\n" #~ " inverse=\"true\"\n" #~ " order-by=\"DATE_TIME\"\n" #~ " cascade=\"all\">\n" #~ "\n" #~ " <key column=\"BLOG_ID\"/>\n" #~ " <one-to-many class=\"BlogItem\"/>\n" #~ "\n" #~ " </bag>\n" #~ "\n" #~ " </class>\n" #~ "\n" #~ "</hibernate-mapping>" #, fuzzy #~ msgid "" #~ "<![CDATA[" #~ msgstr "" #~ "<?xml version=\"1.0\"?>\n" #~ "<!DOCTYPE hibernate-mapping PUBLIC\n" #~ " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" #~ " \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n" #~ "\n" #~ "<hibernate-mapping package=\"eg\">\n" #~ "\n" #~ " <class\n" #~ " name=\"BlogItem\"\n" #~ " table=\"BLOG_ITEMS\"\n" #~ " dynamic-update=\"true\">\n" #~ "\n" #~ " <id\n" #~ " name=\"id\"\n" #~ " column=\"BLOG_ITEM_ID\">\n" #~ "\n" #~ " <generator class=\"native\"/>\n" #~ "\n" #~ " </id>\n" #~ "\n" #~ " <property\n" #~ " name=\"title\"\n" #~ " column=\"TITLE\"\n" #~ " not-null=\"true\"/>\n" #~ "\n" #~ " <property\n" #~ " name=\"text\"\n" #~ " column=\"TEXT\"\n" #~ " not-null=\"true\"/>\n" #~ "\n" #~ " <property\n" #~ " name=\"datetime\"\n" #~ " column=\"DATE_TIME\"\n" #~ " not-null=\"true\"/>\n" #~ "\n" #~ " <many-to-one\n" #~ " name=\"blog\"\n" #~ " column=\"BLOG_ID\"\n" #~ " not-null=\"true\"/>\n" #~ "\n" #~ " </class>\n" #~ "\n" #~ "</hibernate-mapping>" #, fuzzy #~ 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 "" #~ "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.