-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: error in composite PK with one of the key has type of int
PostPosted: Mon Jan 12, 2004 5:20 am 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
Hi all.. I'm new with hibernate..
I have this problem..
I have a table with composite primary key, which one of them has type of integer. it's something like this:

<class name="com.test.Budget" table="Budget">
<composite-id name="compId" class="com.test.PKBudget">
<key-property name="budgetType_" column="budget_type" type="string" length="1"/>
<key-property name="budgetYear_" column="budget_year" type="string" length="4"/>
<key-property name="bonusMonth_" type="string" column="bonus_month" length="2"></key-property> </composite-id>
<property name="bonusRate" not-null="true" type="integer">
<column name="bonus_rate" sql-type="number(3)"/>
</property>

notice that "bonusRate" and "bonusMonth" both have type of "integer".

i'd like "bonusMonth" to have type of "integer" too, but when i generate the hibernate class and call the session.save() for that object,
it always produce/insert INCORRECT value (e.g. 1 becomes 1E6),
while "bonusRate" produce/insert the CORRECT value;

changing the "bonusMonth" into String gives the expected value (i.e the CORRECT one).

has anyone has encountered such problem? please help :)
thanks a lot in advance.

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 8:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you saying that this one fails ?
Code:
<key-property name="bonusMonth_" type="integer" column="bonus_month" > <column name="bonus_rate" sql-type="number(3)"/> </key-property>

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: error in composite PK with one of the key has type of in
PostPosted: Mon Jan 12, 2004 8:54 pm 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
Immanuel, yes, exactly.
when "bonusMonth_" has type of "integer", it stores INCORRECT value,
when I change the type into "String" it stores CORRECT one.

thanks for responding. so what did i do wrong?
thanks a lot

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject: Re: error in composite PK with one of the key has type of in
PostPosted: Mon Jan 12, 2004 8:54 pm 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
Emmanuel, yes, exactly.
when "bonusMonth_" has type of "integer", it stores INCORRECT value,
when I change the type into "String" it stores CORRECT one.

thanks for responding. so what did i do wrong?
thanks a lot

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 8:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I think he is rather doing something like mapping an integer type to a string column in the database. If yes, this does not work of course, without using a custom UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 9:24 pm 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
gloeglm wrote:
I think he is rather doing something like mapping an integer type to a string column in the database. If yes, this does not work of course, without using a custom UserType.


it's not my intention.
what i'd like to do is simply having integer type both in database and in java for column "bonusMonth" (which is a part of a COMPOSITE PRIMARY KEY).

other integer type (both in database and java) stores the CORRECT value, but for "bonusMonth" it doesnt.

thanks for your help. any idea what did i do wrong?
thanks in advance.

regards,
dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 9:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
are you really using integer/int everywhere? Please show your mapping, database schema and composite-id class.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 9:38 pm 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
gloeglm wrote:
are you really using integer/int everywhere? Please show your mapping, database schema and composite-id class.


here is the mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.mycompany.bs115.Gpfb115Abc" table="Gpfb115Abc">
<composite-id name="compId" class="com.mycompany.bs115.PKGpfb115Abc">
<key-property name="budgetType_" column="budget_type" type="string" length="1"/>
<key-property name="budgetYear_" column="budget_year" type="string" length="4"/>
<!--
<key-property name="bonusMonth_" type="string" column="bonus_month" length="2">
-->
<key-property name="bonusMonth_" type="integer" column="bonus_month" >
<column name="bonus_month" sql-type="number(3)"/>
</key-property>
<!-- column name="bonus_month" sql-type="number(10)"/ -->
<key-property name="locationCode_" column="location_code" type="string" length="2"/>
<key-property name="bonusType_" column="bonus_type" type="string" length="2"/>
</composite-id>
<property name="bonusRate" not-null="true" type="integer">
<column name="bonus_rate" sql-type="number(3)"/>
</property>
<property name="lastUpdateDate" column="last_update_date" type="timestamp"/>
<many-to-one name="modifiedBy_" class="com.mycompany.user.Gpfb301" column="modified_by"/>
</class>
</hibernate-mapping>


here is the database schema (generated using hibernate's schemaexport)

create table Gpfb115Abc (
budget_type VARCHAR2(1) not null,
budget_year VARCHAR2(4) not null,
bonus_month NUMBER(10,0) not null,
location_code VARCHAR2(2) not null,
bonus_type VARCHAR2(2) not null,
bonus_rate number(3),
last_update_date DATE,
modified_by VARCHAR2(10),
primary key (budget_type, budget_year, bonus_month, location_code, bonus_type)
);

and here is the PK Class (generated using hibernate's hbm2java.CodeGenerator)

public class PKGpfb115Abc implements Serializable {

/** identifier field */
private String budgetType_;

/** identifier field */
private String budgetYear_;

/** identifier field */
private int bonusMonth_;

/** identifier field */
private String locationCode_;

/** identifier field */
private String bonusType_;

/** full constructor */
public PKGpfb115Abc(String budgetType_, String budgetYear_, int bonusMonth_, String locationCode_, String bonusType_) {
this.budgetType_ = budgetType_;
this.budgetYear_ = budgetYear_;
this.bonusMonth_ = bonusMonth_;
this.locationCode_ = locationCode_;
this.bonusType_ = bonusType_;
}

// the rest of the class is not shown

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
bonus_month NUMBER(10,0) not null,
bonus_rate number(3),

This is a DB type issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:18 am 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
emmanuel wrote:
bonus_month NUMBER(10,0) not null,
bonus_rate number(3),

This is a DB type issue


Umm.. sorry I forgot to mentioned that I'm using Oracle 9i.
Is it known error with hibernate..?

Here's the content of my Hibernate.properties:

hibernate.dialect=net.sf.hibernate.dialect.OracleDialect
hibernate.show_sql=true
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver

and here's the way I set the value
PKGpfb115Abc pk = new PKGpfb115Abc();
pk.setBudgetType_("O");
pk.setBudgetYear_("2003");
pk.setBonusType_("L");
pk.setBonusMonth_(3); // this is the error

tx = session.beginTransaction();
session.save(hib);
session.flush();
tx.commit();

the value 3 becomes 1.42E80 in the first try , -6.6E-79 in the second try...
(consistently generate different values).

thanks a lot in advance.

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:24 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're using NUMBER(10,0) and set number(3) in Hibernate => oracle convert your number.
Try to set NUMBER(3) in DB.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:36 am 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
emmanuel wrote:
You're using NUMBER(10,0) and set number(3) in Hibernate => oracle convert your number.
Try to set NUMBER(3) in DB.


Emmanuel, I did the following:
- alter table gpfb115Abc modify bonus_month number(3);
- commit;

then I set using setBonusMonth_(3)
it stores 6.9000E-29

setBonusMonth(5)
it stores -1.000E+50

I'm scratching my head... any idea why?
Thanks a lot .

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:41 am 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
d10n2000 wrote:
emmanuel wrote:
You're using NUMBER(10,0) and set number(3) in Hibernate => oracle convert your number.
Try to set NUMBER(3) in DB.


Emmanuel, I did the following:
- alter table gpfb115Abc modify bonus_month number(3);
- commit;

then I set using setBonusMonth_(3)
it stores 6.9000E-29

setBonusMonth(5)
it stores -1.000E+50

I'm scratching my head... any idea why?
Thanks a lot .

regards,
Dion


btw, executing direct insert statement gives the expected value like this
INSERT INTO GPFB115ABC (budget_type, budget_year, bonus_month, location_code, bonus_type, bonus_rate, last_update_date, modified_by)
VALUES ('U', '2003', 5, 'L', 'T', 8, SYSDATE, 'user')

regards,
Dion

_________________
~Dion


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try enabling sql and bind parameter logging - what does Hibernate generate and bind?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:54 am 
Newbie

Joined: Mon Jan 12, 2004 2:24 am
Posts: 16
gloeglm wrote:
Try enabling sql and bind parameter logging - what does Hibernate generate and bind?


How to do that, gloeglm?
Looking at the hibernate doc (the pdf one), I could only think of
hibernate.show_sql=true
Thanks.

regards,
Dion

_________________
~Dion


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