-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Configuring Index to map an exhisting index on oracle dbms
PostPosted: Fri Apr 29, 2011 7:32 am 
Beginner
Beginner

Joined: Mon Apr 18, 2011 10:01 am
Posts: 20
Hi everybody,
I would like to configure an index associated with one of the fields of the object which I need to persist,
given that I already defined an index on my DBMS for the corresponding field of my table.

I did something like that :
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="previtc.model.task">
    <class name="PcTask" table="PC_TASK" dynamic-update="true" dynamic-insert="true">
        <id name="taskId" column="TASKID" type="string">
            <generator class="sequence">
                <param name="sequence">PC_TASK_ID_SEQ</param>
            </generator>
        </id>
        <property name="taskNumber"                                             type="double" >
            <column name="TASKNUMBER" not-null="false" index="PC_TASKTASKNUMBER_I" length="22"/>
        </property>
        <property name="acquiredBy"         column="ACQUIREDBY"                 type="string" />
        [......... other fields]
    </class>
</hibernate-mapping>


And in the code, I don't set that field supposing that hibernate will do that, giving it the next value of the index. Is this correct ?


Top
 Profile  
 
 Post subject: Re: Configuring Index to map an exhisting index on oracle dbms
PostPosted: Fri Apr 29, 2011 8:16 am 
Beginner
Beginner

Joined: Mon Apr 18, 2011 10:01 am
Posts: 20
basically I need to autoincrement a non primary key field. Something like that is discussed here:

viewtopic.php?f=25&t=960132&start=0

but it's a bit too far from my know how :O

any hint plz ?


Top
 Profile  
 
 Post subject: Re: Configuring Index to map an exhisting index on oracle dbms
PostPosted: Fri Apr 29, 2011 8:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess all you need is to add generated="insert" insert="false" update="false" to the <property> tag in your mapping file.

For more information: http://docs.jboss.org/hibernate/core/3. ... -generated


Top
 Profile  
 
 Post subject: Re: Configuring Index to map an exhisting index on oracle dbms
PostPosted: Fri Apr 29, 2011 9:05 am 
Beginner
Beginner

Joined: Mon Apr 18, 2011 10:01 am
Posts: 20
Thank you for your reply,

I mapped my bean as follows :

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="previtc.model.task">
    <class name="PcTask" table="PC_TASK" dynamic-update="true" dynamic-insert="true">
        <id name="taskId" column="TASKID" type="string">
            <generator class="sequence">
                <param name="sequence">PC_TASK_ID_SEQ</param>
            </generator>
        </id>
        <property name="taskNumber" generated="insert" type="java.lang.Integer" insert="false" update="false">
            <column name="TASKNUMBER" not-null="true" unique="true" />
        </property>
        <property name="acquiredBy"         column="ACQUIREDBY"                 type="string" />
        <property name="approvers"          column="APPROVERS"                  type="string" />
        [... other fields ...]
    </class>
</hibernate-mapping>


and on my schema I have the field TASKNUMBER as nullable=false. But when I try to insert in my database an object of the type
PCTASK , I got complained that ORA-01400: cannot insert NULL into ("PREVITC"."PC_TASK"."TASKNUMBER") .
This is obviously because when I instantiate an object PcTask, I do not assign any value to his TASKNUMBER field, because I want
it to be generated at the moment of the Insert statement.

Do you have any suggestions ? Thanks a lot in advance , I really appreciate your help cause I'm noob and stuck


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.