Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: formatting changes

...

Panel
borderStylesolid
titleTable of contents
Table of Contents
minLevel2

Simple master-detail example

...

Working on my wicketWicket/databinder/hibernate Hibernate application I've run into a problem, how . How I can show master-detail relation entities , are extracted from the database? No doubt , there are tens ways , how to do this, but I wanted to exploit mature and conviniet convenient Hibernate's lazy loading facility and avoid an odd code cluttering.

Say there is an Order entity list with list of its Items is shown in a master table. Order Items Set is a member, declaried declared with Hibernate @OneToMany annotation, must be shown on neighbour table.

...

Entity Code

...

Code Block
java
java
@Entity
public class Order {
@Id Integer orderId;
@Column Integer number;
...
@OneToMany
Set<OrderItem> items;
...
}

@Entity
public class OrderItem {
@Id Integer itemId;
@Column String itemName;
...
}

...

Markup code

...

Code Block
html
html
titleHomePage.html


<html>
    <body>
               
       <table cellspacing="0" cellpadding="2" border="1">
               <tr wicket:id="orders">
                       <td><span wicket:id="orderId">[order id]</span></td>
                       <td><a wicket:id="alink"><span wicket:id="number">[order number]</span></a></td>
               </tr>
       </table>

       <div wicket:id="itemsWrap"></div>
    </body>
</html>


                       
Code Block
html
html
titleHomePage$ItemsPanel.html


<wicket:panel>
       <table cellspacing="0" cellpadding="2" border="1">
               <tr wicket:id="items">
                       <td><span wicket:id="itemId">[id]</span></td>
                       <td><span wicket:id="itemName">[name]</span></td>
               </tr>
       </table>
</wicket:panel>

...