Results 1 to 6 of 6
  1. #1
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default Oracle sequences

    I am wondering how to get oracle sequence to increment the primary key for my tables from my object.

  2. #2
    pegitha is offline Member
    Join Date
    Apr 2007
    Location
    Indiana
    Posts
    83
    Rep Power
    0

    Default

    Can I see your mapping file?

  3. #3
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Here
    Java Code:
    <?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 package="domain">
    	
    
    	<class name="TfoType" table="TFO_TYPE" lazy="false">
    
    		<id name="id" type="java.lang.Integer" column="ID">
    			<generator class="assigned" />
    		</id>
    
    		<property name="description" type="java.lang.String" column="DESCRIPTION" not-null="true" length="50" />
    		<property name="creationDate" type="java.sql.Timestamp" column="CREATION_DATE" not-null="true" length="7" />
    		<property name="createdBy" type="java.lang.String" column="CREATED_BY" not-null="true" length="8" />
    		<property name="lastUpdated" type="java.sql.Timestamp" column="LAST_UPDATED" length="7" />
    		<property name="lastUpdatedBy" type="java.lang.String" column="LAST_UPDATED_BY" length="8" />
    		<property name="recordStatus" type="java.lang.String" column="RECORD_STATUS" not-null="true" length="1" />
    	</class>
    </hibernate-mapping>
    Last edited by orchid; 04-19-2007 at 03:08 AM.

  4. #4
    pegitha is offline Member
    Join Date
    Apr 2007
    Location
    Indiana
    Posts
    83
    Rep Power
    0

    Default

    Depending on how your database is set up , that could work. But if it is not working, then try this:
    Java Code:
    <id name="id" type="java.lang.Integer" column="ID">
     <generator class="sequence" />
       <param name="sequence">TFO_TYPE_SEQ</param>
     </generator>
    </id>
    It tells oracle that it is a sequence and exactly which one to use.

  5. #5
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default Assumption : Using hibernate

    Above assumes you are using hibernate for saving the entities,
    Else you can simply say select sequencename.nextval from dual which will return the next value of the sequence and assign to some id and execute as a JDBC insert query

  6. #6
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

Similar Threads

  1. Generating number sequences
    By hawkmauk in forum New To Java
    Replies: 0
    Last Post: 11-15-2007, 03:32 PM
  2. MS SQL2005 to Oracle DB
    By bmongtangco in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-07-2007, 02:58 AM
  3. Oracle and JDBC
    By Eric in forum JDBC
    Replies: 3
    Last Post: 08-11-2007, 08:49 PM
  4. oracle problem
    By Peter in forum JDBC
    Replies: 1
    Last Post: 07-09-2007, 04:19 AM
  5. Oracle Driver
    By softy in forum JDBC
    Replies: 1
    Last Post: 07-02-2007, 12:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •