in this xml mapping file :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  <class dynamic-insert="false" dynamic-update="false"
      mutable="true" name="travel.Person" optimistic-lock="version"
      polymorphism="implicit" select-before-update="false" table="PERSON">
        <id column="PERSONID" name="personId">
            <generator class="increment"/>
        <property column="NAME" name="name"/>
        <property column="JOBTITLE" name="jobTitle"/>
        <property column="FREQUENTFLYER" name="frequentFlyer"/>
        <set cascade="all-delete-orphan" inverse="true" lazy="true" name="trips" table="TRIP">
            <key column="PERSONID"/>
            <one-to-many class="travel.Trip"/>

what does this code do?

<id column="PERSONID" name="personId">
            <generator class="increment"/>
8 Years
Discussion Span
Last Post by nsisupalan

<id/> tag will define colum "PERSONID" as the primary key for the object Person. It is not required in hibenate that PERSONID colum is a primary key to be declared as a primary key for the object.
Generator = increment means hibernate will treat this column like an AUTO GENERATED or SEQUENCE. When you save a Person object you dont have to pass a value for PERSONID. Hibernate will generate i for you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.