-->
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.  [ 3 posts ] 
Author Message
 Post subject: Oracle rownum on Mapping
PostPosted: Fri Sep 19, 2008 10:08 pm 
Newbie

Joined: Fri Sep 19, 2008 10:00 pm
Posts: 1
Location: Philippines
have a table that there is no primary key. what ive done on my mapping file is I refer the ID to the column rownum so that I get a primary key. But hibernate return unknown column exceptions, which is I believe rownum exist on every table. What should I do to make rownum visible to the hibernate?


Thanks and regardz,
Allen Montejo


Top
 Profile  
 
 Post subject: rownum is only in Oracle
PostPosted: Sat Sep 20, 2008 12:11 am 
Newbie

Joined: Fri Sep 19, 2008 6:59 am
Posts: 6
Rownum is only in Oracle, it's not present there in DB2 atleast, so you can't make use of it in Hibernate(atleast this is what i think).
Further, why is it that you don't want to define a Primary key for that table.
Relational laws state that every table should have a PK(although databases are too lenient in this regard and allow the creation of a table without a PK).

Anyways, i think you cannot use rownum because Hibernate will (should) not recognize it.

_________________
Rahul


Top
 Profile  
 
 Post subject: Re: Oracle rownum on Mapping
PostPosted: Tue Oct 14, 2008 4:37 pm 
Newbie

Joined: Thu Oct 09, 2008 4:03 pm
Posts: 16
Location: US, Itasca Illinois
Don't use rownum as a primary key in Oracle. If you wish to automatically generate a primary key, you can use a sequence. Add something similar to this to your mapping file:

<class name="com.service.persist.domain.BssDaily" table="BSS_DAILY">
<id name="id" column="BSS_DAILY_ID">
<generator class="sequence">
<param name="sequence">bss_daily_seq</param>
</generator>
</id>

In my code, bss_daily_seq was an Oracle sequence, and bss_daily_id was a numeric column defined on oracle table bss_daily. "id" was a proprty in my Java object.

You will need to define the sequence in a tool such as Oracle Developer. Worked well in Hibernate 3.3.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.