I have an Oracle database table
Account
-------------
Acct_ID - Integer
Acct_Num - varchar2
Acct_Name - varchar2
I use an Oracle sequence to generate Acct_ID
I have the mapping document set up this way
Code:
<!DOCTYPE hibernate-mapping PUBLIC '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping>
<class name="com.stlouiscity.budget.database.beans.AccountBean" table="Budget.Account">
<id name="acctId" column="Acct_ID" type="integer" >
<generator class="sequence">
<param name="sequence">Acct_ID_SQ</param>
</generator>
</id>
<property name="acctNum" type="string" column="Acct_Num"></property>
<property name="acctName" type="string" column="Acct_Name"></property>
</class>
</hibernate-mapping>
I wish to use the saveOrUpdate convienence method to insert/update records. What I want to know is how do I initialize my bean's id field? If I use int then I have to initialize it to 0. How will saveOrUpdate know how to issue an insert and use the sequence if the value is already popluated as zero? Won't Hibernate just issue an update? Should I use a java.lang.Integer instead so it can be initialized to null? If yes, how do I map this in the type attribute in the hbm file for the id field? Any guidance on how to handle inserts