Tasklist Hibernate 3 HBM file

  1. Create a java package to hold the hibernate hbm file
    1. Right click on the java src folder (tool/src/java) and select New -> Package
      • Note: sometimes a new source folder is created for hibernate files (e.g. tool/src/hibernate)
    2. For the name enter: org.sakaiproject.tool.tasklist.hibernate
  2. Create a new file by right clicking on the package and selecting New -> File
  3. Enter the name for the file as: Task.hbm.xml
  4. Start with this simple HBM file template and paste this text into the new file:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    		"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping>
    	<class name="org.sakaiproject.tool.MyTool.MyClassImpl" table="MYTOOL_MYCLASS">
    		<id name="id" type="long" column="MYCLASS_ID">
    			<generator class="native">
    				<param name="sequence">MYCLASS_ID_SEQ</param>
    			</generator>
    		</id>
    
    		<property name="myProperty" type="string" length="255" not-null="true">
    			<column name="MY_PROPERTY"/>
    		</property>
    	</class>
    </hibernate-mapping>
    
    • We want to create an HBM which will create a mapping between the Task and the database
  5. Change the class name to org.sakaiproject.tool.tasklist.impl.TaskImpl
  6. Change the class table to TASKLIST_TASKS
  7. Change the id column to TASK_ID (optional, but do not leave as the template default)
  8. Change the id generator param to TASKLIST_TASK_ID_SEQ (optional, but must be unique)
  9. Next we need to add in the 4 properties from the Task object
    We will use the hibernate native types in this example
    • owner - the creator of the task
    • siteId - the site this task was created in
    • creationDate - when was the task created
    • task - the text of the task
  10. Create the property mapping for the owner property
    <property name="owner" type="string" length="255" not-null="true">
            <column name="TASK_OWNER"/>
    </property>
    
    • This will contain the userId string (which will be a big long number with dashes in it)
    • type - hibernate native string
    • length - 255 chars
    • cannot be null
  11. Create the property mapping for the siteId property
    <property name="siteId" type="string" length="255" not-null="true">
    	<column name="TASK_SITE_ID"/>
    </property>
    
    • This will contain the siteId string (e.g. mercury)
    • type - hibernate native string
    • length - 255 chars
    • cannot be null
  12. Create the property mapping for the creationDate property
    <property name="creationDate" type="timestamp" not-null="true">
    	<column name="TASK_CREATION_DATE"/>
    </property>
    
    • This will contain the date and time the task object was created
    • type - hibernate native timestamp (date and time)
    • cannot be null
  13. Create the property mapping for the task property
    <property name="task" type="text" not-null="true">
    	<column name="TASK_TEXT"/>
    </property>
    
    • This will contain the text of the task itself (could be any length)
    • type - hibernate native text (unlimited string)
    • cannot be null
  14. HBM file creation complete


  File Modified

XML File Template.hbm.xml Blank hbm file template for hibernate 3

May 22, 2006 by Former user