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.  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: how to change ID type from long to Long?
PostPosted: Wed Aug 16, 2006 5:35 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b] 3.2 cr3

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:[/b] Oracle 9.2

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]

Need id field in generated hbm file from
<id name="orderId" type="long">
to
<id name="orderId" type="Long">

I am using Hibernate Tools 3.2.0.beta6a. I have tried putting something as below in reverse engineering file, but didn't work.

<sql-type jdbc-type="DECIMAL" precision="19" scale="0" hibernate-type="Long" />

Can anyone tell me a way for this purpose? Thanks!


Top
 Profile  
 
 Post subject: Changing type to a Long
PostPosted: Wed Aug 16, 2006 5:44 pm 
Newbie

Joined: Wed Aug 16, 2006 4:25 pm
Posts: 3
Location: Denver
Not sure why you would want to do this, but try putting something like this in your reverse engineering file:

<type-mapping>
<sql-type jdbc-type="NUMERIC" precision="19" hibernate-type="java.lang.Long"/>
</type-mapping>

This should change all the occurences to the type Long like you want.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 6:48 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Not work, still return the same long type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 1:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so your column is not of that type and precision.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 10:55 am 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
My ID column is defined as a number(10) in Oracle 9.2, but still gets long as hbm return type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 10:59 am 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
returned as below for both rev engineering file sql-type set as "Long" and "java.lang.Long",

<id name="orderTemplateSiteId" type="long">
<column name="ORDER_TEMPLATE_SITE_ID" precision="10" scale="0" />

<generator class="assigned" />
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you id generator is assigned. The value can/should never be null.

plus you use precision 19 and not precision 10 in your reveng.xml ...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 12:40 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Don't quite understand your point. First, I don't want my ID generator=assigned, I have to change to sequecne generation manually. If you know a way having sequence generator in hbm directly, please let me know. Second, precision 19 means any number whose digit is less than 19 will be treated as long, which is correct in my case since I have got only 10 digits. Don't know what is connected between precision and my return type question. Also I have tried no precision defined in sql-type but still get long return type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
"Second, precision 19 means any number whose digit is less than 19 "

what do you base that statement on ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 12:57 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Correct me if I am wrong. That is based on Tool's predecessor, MiddleGen, source code. Although I don't have a look at Tool's source code, I believe there should be a similar way to determine return type for long, int, etc based on length of digits.

BTW, Do you know how to set up ID generator=sequence directly? Why can't I have Long type? THanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 3:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well this is hibernate tools, not middlegen and actually there is about zero code shared between them at this point.

And yes, a different id generator is possible via reveng.xml and the <generator> attribute.

check the docs, they are worth a read ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 10:09 am 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
Thanks, I will take a look at doc about it. Meanwhile, do you have any idea why I can't have Long in ID field as return type?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 10:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? I answered that about 2 times in this thread ;)

or am i misunderstanding what you are asking for ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:23 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
After I have tried put precision=10, I can see return type=Long in ID field. Thanks!

However, sequence generator doesn't work after I tried as below. In my case, this sequence generator is applied to all tables, so I put "@table.name@" there without <key-column> specified since it is different in each table.

<table name="@table.name@">
<primary-key>
<generator class="sequence">
<param name="table">SEQ_SCHEDULE_ID</param>
</generator>
</primary-key>
</table>

Even I have tried putting a concrete table as below, I am still out of luck having sequence generator in hbm ID field.

<hibernate-reverse-engineering>
<schema-selection match-schema="@schema.name@"
match-table="@table.name@" />
<type-mapping>
<!-- jdbc-type is name fom java.sql.Types -->
<sql-type jdbc-type="DECIMAL" precision="10" scale="0"
hibernate-type="Long" />
</type-mapping>
<table name="ORDER_TYPES">
<primary-key>
<!-- setting up a specific id generator for a table -->
<generator class="sequence">
<param name="table">SEQ_SCHEDULE_ID</param>
</generator>
<key-column name="ORDER_TYPE_ID"/>
</primary-key>
<column name="ORDER_TYPE_NAME" property="orderName" type="string" />
</table>
</hibernate-reverse-engineering>

Generated hbm ID field is like,

<id name="orderTypeId" type="Long">
<column name="ORDER_TYPE_ID" precision="10" scale="0" />

<generator class="assigned" />
</id>

Do you have any idea? Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:28 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
I guess there is someting wrong in <generator class="sequence">. I don't have a class called sequence. What I have in Oracle is only a sequence, and I want to put this sequence in all hbms' ID fields.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ]  Go to page 1, 2  Next

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.