-->
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.  [ 1 post ] 
Author Message
 Post subject: Strange behaviour in table creation
PostPosted: Wed Apr 20, 2011 11:45 am 
Newbie

Joined: Wed Apr 20, 2011 11:30 am
Posts: 1
Hi Hibernate-Team,

I think I found a bug in the ddl-generation out of an annotated entity.
Trying Hibernate 3.6.1 and 3.6.3

I have an entity containing a column with an max length as shown below:
Code:
@Column(name = "Name", columnDefinition = "varchar", length = 100)
private String name;


The generated DDL looks like this, but it doesn't contain the expected length:
Code:
create table Category (
   id bigint identity not null,
   name varchar null,
   primary key (id)
)


After debugging I recognized an strange behaviour inside the Method:
org.hibernate.mapping.Column.getSqlType(Dialect dialect, Mapping mapping)
Code:
public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
    return sqlType==null ?
        dialect.getTypeName( getSqlTypeCode(mapping), getLength(), getPrecision(), getScale() ) :
        sqlType;
}


The sqlType is not null, so this method returns "varchar", but the method "dialect.getTypeName" would return "varchar(100)". So I think the method should look SOMETHING like this:
Code:
    public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
        if(sqlType == null || sqlType.equals("varchar")) {
            return dialect.getTypeName( getSqlTypeCode(mapping), getLength(), getPrecision(), getScale() ) ;
        } else {
            return sqlType;
        }
    }


What do you think?

Greetings,
Sebastian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.