alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (ItemBid.hbm.xml)

This example Hibernate source code file (ItemBid.hbm.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

auctionbids, auctionbids, auctioncomments, auctioncomments, auctionitems, bid, bid, category, comment, doctype, dtd, item, item, mapping

The Hibernate ItemBid.hbm.xml source code

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<!-- 

     
-->

<hibernate-mapping 
	package="org.hibernate.test.joinfetch"
	default-access="field">
	
	<class name="Category" table="AuctionCategories">
		<id name="name"/>
	</class>
	
	<class name="Item" table="AuctionItems">
		<id name="id">
			<generator class="increment"/>
		</id>
		<property name="description" not-null="true"/>
		<many-to-one name="category" not-null="true"/>
		<set name="bids" cascade="all" fetch="join" inverse="true" order-by="`timestamp`">
			<key column="item"/>
			<one-to-many class="Bid"/>
		</set>
		<set name="comments" cascade="all" fetch="join" inverse="true" order-by="`timestamp`">
			<key column="item"/>
			<one-to-many class="Comment"/>
		</set>

		<sql-query name="all">
			<return alias="item" class="Item"/>
			<return-join alias="bid" property="item.bids"/>
			<return-join alias="commnt" property="item.comments"/>
			select {item.*}, {bid.*}, {commnt.*} 
			from AuctionItems item
				left outer join AuctionBids bid on bid.item = item.id
				left outer join AuctionComments commnt on commnt.item = item.id
		</sql-query>

	</class>
	
	<class name="Bid" table="AuctionBids">
		<id name="id">
			<generator class="increment"/>
		</id>
		<property name="amount" not-null="true"/>
		<property name="timestamp" column="`timestamp`" not-null="true"/>
		<many-to-one name="item" fetch="join" not-null="true"/>
	</class>

	<class name="Comment" table="AuctionComments">
		<id name="id">
			<generator class="increment"/>
		</id>
		<property name="text" not-null="true"/>
		<property name="timestamp" column="`timestamp`" not-null="true"/>
		<many-to-one name="item" fetch="join" not-null="true"/>
	</class>
	
</hibernate-mapping>

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate ItemBid.hbm.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.