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

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

This example Hibernate source code file (CustomSQL.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

doctype, dtd, groupid, hibernate/hibernate, intervention, intervention, mapping, mapping, medication, medication, person, resource, role, role

The Hibernate CustomSQL.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 default-lazy="false" package="org.hibernate.test.legacy">
	<class name="Role">

		<id name="id" type="long">
			<generator class="native"/>
		</id>
		
		<property name="name" type="string"/>
		
		<set name="interventions" lazy="true" cascade="all">
			<key column="role_id"/>
			<one-to-many class="Intervention"/>
			<sql-insert callable="false">/* max comment */
				update Intervention set role_id=? where id=?</sql-insert>
			<sql-delete callable="false">update Intervention set role_id=null where role_id=? and id=?
			<sql-delete-all callable="false">update Intervention set role_id=null where role_id=?
		</set>
		
		<list name="bunchOfStrings">			
			<key column="GROUPID"/>
			<index column="posn"/>
		    <element column="NAME" type="string"/>
			<sql-insert callable="true">{ ? = call createRoleBunchOfStrings(?, ?, ?)}
			<sql-update callable="true">{ ? = call updateRoleBunchOfStrings(?, ?, ?)}
			<sql-delete callable="true">{ ? = call deleteRoleBunchOfString(?, ?)}
			<sql-delete-all callable="true">{ ? = call deleteAllRoleBunchOfString(?)}
		</list>
		
<!--		
		<sql-insert callable="true">{call createPatient (?, ?, ?, ?)}
		<sql-delete callable="true">{? = call deletePatient (?)} 
		<sql-update callable="true">{? = call updatePatient (?, ?, ?, ?)} -->
<!--	 -->
<!--		   -->
		<sql-insert>insert into Role (name, id) values (?, upper(?)) /** i did this */  
<!--		-->
		<sql-delete>delete from Role where id=?
		
	</class>	
	
	<class name="Resource" table="ecruoser">
		<id name="id" type="string">
			<generator class="uuid.hex"/>
		</id>
		
		<discriminator column="discriminator" type="string"/>
		
		<property name="name" type="string"/>
		<property name="userCode" type="string"/>
		
		<subclass name="Drug">
			
		</subclass>
	</class>
	
	<class name="Party">
		<id name="id" type="string">
			<generator class="uuid.hex"/>
		</id>
		<discriminator column="discriminator" type="string"/>
		<join table="partyjointable">
			<key column="partyid"/>
     		<property name="name" column="xname" type="string"/>
	    	<property name="address" type="string"/>
			<sql-insert callable="true">{ call createJoinTable(?, ?, ?) }			
			<sql-update callable="true">{ ? = call updateJoinTable(?, ?, ?) } 
			<sql-delete callable="true">{ ? = call deleteJoinTable(?) } 
		</join>
							
		<subclass name="Person">
			<property name="givenName" type="string"/>			
			<property name="lastName" type="string"/>		
			<property name="nationalID" unique="true" type="string"/>
		</subclass>		

		<subclass name="Company">
		   <property name="president" type="string"/>
		</subclass>				
	</class>
	
	<class name="Intervention">
		<id name="id" type="string">
			<generator class="uuid.hex"/>
		</id>
		
		<version name="version" type="long"/>
		
		<property name="description" type="string"/>
		
		<joined-subclass name="Medication">
			<key column="interventionid"/>
			<many-to-one name="prescribedDrug" class="org.hibernate.test.legacy.Drug"/>			
			<sql-insert>insert into /** put weird comments here */ Medication (prescribedDrug, interventionid) values (?, ?) 
		</joined-subclass>
		
	</class>
	
	
	
</hibernate-mapping>

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate CustomSQL.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.