background preloader

Hibernate

Facebook Twitter

Lucene

Cache. REVERT TO CONSOLE » Blog Archive » Automated Unit Testing with D. Building a tag cloud in Java. You've seen them. Maybe you like them, maybe not, but Tag clouds are here to stay (at least until someone invents something better). This article details how the tag cloud for this web site was created. This site uses Hibernate (with Annotations) and Spring extensively, but while this article will make use of those frameworks, the same general concepts apply no matter what frameworks you choose to use (or not use). The first step to bulding a Tag cloud is being able to map Articles to Tags (and vice-versa, which will be clear in a moment). The relevant code in Article.java is as follows: private List<Tag> tags; @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable( name = "article_tag_link", joinColumns = { @JoinColumn(name = "article_id") }, inverseJoinColumns = @JoinColumn(name = "tag_id")) @OrderBy("displayName") public List<Tag> getTags() { return tags; } There are a few points to note about this code.

To make use of these queries, we define a few DAO interfaces: [Code] org.hibernate.test.criteria.CriteriaQueryTest _ Java API. Hibernate Querying 101 : tips and tricks. This article presents a few real-life tips and tricks for Hibernate querying. It is designed to be a 'from-the-trenches' account of the methods and best-practices we use and that we have found to work. Background First a little background. We are currently working on a project using a JSTL / Struts / Hibernate / PostgreSQL stack. The application requires many PDF reports. For the PDF (and Excel) report generation, we use JasperReports. Maybe I'll write another article on JasperReports some other time. The reports tend to be complicated. Hibernate Query Methods The queries we general use can be divided up into three main categories : Simple HQL queries using one class (where no joins are required) HQL queries which require joins over several classes HQL queries which cannot be efficiently done using joins Simple HQL queries The first and simplest query is the plain old HQL query on one object, as you can find in all the Hibernate introductory examples : Queries using joins or Conclusion.

Sessions and transactions. Hibernate Mapping Cheat Sheet. A many-to-many reference is basically a collection. Class A holds a reference to a set of class B instances (as in the one-to-many case), but B might have multiple A's. Scenario We have two classes, Foo and Bar which are related to each other as follows: Set Foo.getBars() // of Bar instances<class name="Foo" table="foo"> ... <set role="bars" table="foo_bar"><key column="foo_id"/><many-to-many column="bar_id" class="Bar"/></set> </class> This time we cannot have an extra column on Bar as that would dictate that each Bar has only one Foo. So instead we have an extra table, foo_bar, which holds the relationship between instances.

Bidirectionality This relationship can be declared both ways, with Bar having getFoos(), by suitable code changes to Bar and the following schema change: <class name="Bar" table="bar"> ... Now your Bars will know who their Foos are. No extra columns are generated for the bidirectionality. Appfuse: AppFuse. Www.hibernate.org - Explanation of inverse mapping.