-->
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: Schema-validation: wrong column type encountered in column
PostPosted: Tue May 23, 2017 2:17 am 
Newbie

Joined: Tue Jun 07, 2016 10:38 pm
Posts: 3
Location: South East Asia
When upgrading to v5.2 from v4, Hibernate doesn't seem to approve of the numeric type for identity fields any longer.

Code:
Schema-validation: wrong column type encountered in column [ID] in table [dbo.ACCOUNT]; found [numeric (Types#NUMERIC)], but expecting [bigint (Types#BIGINT)]


The database is a SQL Server 2008 where tables are generated as:

Code:
CREATE TABLE [dbo].[ACCOUNT](
[ID] [numeric](19, 0) IDENTITY(1,1) NOT NULL,
...
);


Is there a way to resolve this without changing the schema or changing the annotations in a couple of hundred java files?


Additional properties used are:
Code:
spring.datasource.url=jdbc:jtds:sqlserver://localhost:1433/stagingdb
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.default_schema=dbo


The JDBC driver used is jTDS v1.3.1, I tried with Microsofts own driver without any luck.

Thank you.


Top
 Profile  
 
 Post subject: Re: Upgrading to v5 from v4, validation fails on @Id columns.
PostPosted: Tue May 23, 2017 2:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Usually, an INT or BIGINT column type is what you expect on an IDENTITY column. Since you haven't provided the Hibernate entity mapping, I assume you have a Long on the Java side.

The java.lang.Long type is handled by LongType, which uses the BigIntTypeDescriptor to handle the JDBC and SQL type mapping. On the other hand, the BigIntegerType uses a NumericTypeDescriptor, so it expects a NUMERIC column on the database part.

Therefore, you can change the identifier type from Long to BigInteger. To minimize the impact on the application-side, you can hide this at the field level, and allow the getters and setters to use Long:

Code:
@Id
private BigInteger id;

public Long getId() {
   return id.longValue();
}

public void setId(Long id) {
   this.id = BigInteger.valueOf( id );
}


Top
 Profile  
 
 Post subject: Re: found [numeric (Types#NUMERIC)], expecting Types#BIGINT
PostPosted: Tue May 23, 2017 4:00 am 
Newbie

Joined: Tue Jun 07, 2016 10:38 pm
Posts: 3
Location: South East Asia
Vlad,
many thanks for your insightful reply.

It's a nice workaround you suggested, I will try it out and see the impact.
In worst case I simply have to sit down one night and correct the schema to what Hibernate expects. :)


Top
 Profile  
 
 Post subject: Re: found [numeric (Types#NUMERIC)], expecting Types#BIGINT
PostPosted: Tue May 23, 2017 4:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Actually, I replicated your example with this test and wrote an article about it.

The fix is quite simple, just annotate the @Id column like this:

Code:
@Id
@GeneratedValue
@Column(columnDefinition = "NUMERIC(19,0)")
private Long id;


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.