-->
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.  [ 8 posts ] 
Author Message
 Post subject: wrong column type in hibernate
PostPosted: Tue Nov 18, 2008 9:40 am 
Newbie

Joined: Tue Nov 18, 2008 5:29 am
Posts: 4
Hibernate version: 3

Jboss 4.2 + Seam2.1 + Hibernate3 in Eclipse Ganymede

I´m trying to built an application that serch for results in an SQL Server 2005 table.
This table have some columns of type decimal(5,2), and i have declare the fields on the entity to receive them as BigDecimal.
But wend running on Jboss i get the this error:



Code:

12:50:16,338 INFO  [TableMetadata] table found: PES.dbo.FuncFerias
12:50:16,338 INFO  [TableMetadata] columns: [dias_ferias, dias_suplement, dias_por_gozar, dias_antig, numero, obs, data_login, ano, login, dias_descontados, dias_gozados, rowid, dias_acumulados, dias_idade]
12:50:16,338 WARN  [ServiceController] Problem starting service persistence.units:ear=seamFerias-ear.ear,unitName=seamFerias
javax.persistence.PersistenceException: [PersistenceUnit: seamFerias] Unable to build EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
   ...
   at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Wrong column type in PES.dbo.FuncFerias for column dias_acumulados. Found: decimal, expected: numeric(19,2)
   at org.hibernate.mapping.Table.validateColumns(Table.java:284)



I suppose it have to do whit the Dialect file in hibernate, but i don´t know how to solve it.

Does any one know it?

Thanks for the attention

Paulo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 5:28 am 
Newbie

Joined: Tue Nov 18, 2008 5:29 am
Posts: 4
Any One can help me?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 8:13 pm 
Newbie

Joined: Thu Nov 20, 2008 1:08 am
Posts: 9
Hi,

I'm not sure if this helps, but it looks like you're probably having the same problem I'm having:

http://forum.hibernate.org/viewtopic.php?t=992509

Which JDBC driver are you using, Microsoft or JTDS or something else? If you're using the Microsoft JDBC driver, you might want to try the JTDS driver instead, that may resolve your problem, since switching from JTDS to the Microsoft driver is what causes our problem.

HTH,

Rob Hills
Waikiki, Western Australia


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 4:42 am 
Newbie

Joined: Thu Nov 20, 2008 1:08 am
Posts: 9
Our problem turned out to be due to a UserType we had on our column, details on the thread in my previous post.

HTH,

Rob Hills
Waikiki, Western Australia


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 6:05 am 
Newbie

Joined: Tue Nov 18, 2008 5:29 am
Posts: 4
Hello Rob tanks for your reply,

Curiously i have read your topic before and have switched the SQLServerDriver for the jTDS one and it have solved some problems but not this one, i still got this error.

I'm working with an old database that i can´t change so i must find another solution for my problem. I really still think that it have to do with the Dialect
that i am using

SQLServerDialect in Hibernate

Code:
...
registerHibernateType( Types.NUMERIC, Hibernate.BIG_DECIMAL.getName() );
registerHibernateType( Types.DECIMAL, Hibernate.BIG_DECIMAL.getName() );
...


Where the two types are treated in the same way like BigDecimal by the Hibernate.
And i think that may causes the the error, but don´t know how to solve it.

Tanks again for your reply

Paulo Caeiro
Évora, Portugal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 8:24 am 
Newbie

Joined: Thu Nov 20, 2008 1:08 am
Posts: 9
Hi Paolo,

I downloaded the Hibernate source and stepped through it to find out the cause of our problem. I also looked through the Dialect file and I'd be surprised if that was your problem.

If you have the source and can step through it, you will probably be able to work out what's going on. From memory, in the org.hibernate.mapping.Table.validateColumns(..) method, it compares the datatype obtained from the DB metadata with the datatype in its mappings (a combination of the DB Dialect and sundry other bits and pieces AFAICT) and then throws the exception you see if they don't match.

You can influence the DataType yourself by using a custom UserType, which is what we'd done, we were just returning a type that happened to work with the jTDS driver but not the M$ one.

Have you tried playing with the datatype in your entity class? You may be able to get it working if you set the size and precision using hibernate annotations. Can you post the source for your entity that you have a problem with?

Cheers,

Rob Hills
Waikiki, Western Australia


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 1:11 pm 
Newbie

Joined: Tue Nov 18, 2008 5:29 am
Posts: 4
Hello Rob once again,

You ware right, it was so simple after all.....

I have just follow your advice and after some research a easily found the solution

Code:
@Column (name="dias_acumulados", columnDefinition="decimal", precision=5, scale=2)      
private BigDecimal dias_acumulados;   



This problem just confirm to me what i suspected already, i should read some stuff before i start trying on Hibernate... :))

Thank you for all Rob...

Paulo Caeiro
Évora, Portugal


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 22, 2008 1:59 am 
Newbie

Joined: Thu Nov 20, 2008 1:08 am
Posts: 9
Hi Paulo,

Glad I could help. You may want to rate the reply that helped ;-)

WRT the reading, it always helps, but the frameworks are often so easy these days that we all tend to dive in and then start reading when we get stuck. It's not the ideal way to do things, but few of us are in projects where they pay us to read!

Cheers,

Rob Hills


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