-->
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.  [ 2 posts ] 
Author Message
 Post subject: @AttributeOverride behavior
PostPosted: Fri Aug 27, 2010 1:57 pm 
Newbie

Joined: Fri Aug 27, 2010 11:55 am
Posts: 2
Given these classes:

Code:
@Embeddable
public class E { ...
    @Column(nullable=false, precision=20, scale=6)
    private BigDecimal a;
}

@Entity
public class C { ...
    @AttributeOverride(name="a", column=@Column(name="b"))
    private E e;
}


What are the expected attributes for column "b"?

I thought I would get the new column name and the same nullable, precision and scale (false, 20, 6). But I got nullable=true, precision=19 and scale=2 (values which I don't know where they come). Not even a defaulted column with the new name.


Top
 Profile  
 
 Post subject: Re: @AttributeOverride behavior
PostPosted: Thu Jan 27, 2011 11:26 am 
Newbie

Joined: Thu Jun 25, 2009 9:11 am
Posts: 1
The reason you get a numeric(19,2) is because these are the defaults implemented in org.hibernate.mapping.Column :-

Code:
   public static final int DEFAULT_LENGTH = 255;
   public static final int DEFAULT_PRECISION = 19;
   public static final int DEFAULT_SCALE = 2;


I've gotten around this by extending org.hibernate.dialect.PostgreSQLDialect :-

Code:
public class ImprovedPostgreSQLDialect extends PostgreSQLDialect {
   @Override
   public String getTypeName(int code, int length, int precision, int scale) throws HibernateException {
      if (Types.NUMERIC == code && precision == org.hibernate.mapping.Column.DEFAULT_PRECISION &&
            scale == org.hibernate.mapping.Column.DEFAULT_SCALE ) {
         return "numeric";
      }
      return super.getTypeName(code, length, precision, scale);
   }
}


which will return the more general "numeric" definition for the column instead of "numeric(19,2)". Note that this is not a perfect solution as you lose the ability to specify the precision in your database and instead rely on the face that you BigDecimal objects are set at the correct precision instead.


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