Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How can I avoid repeating my column definitions?
PostPosted: Sat Apr 14, 2012 11:53 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
I have defined a class called Time which stores a time value as a BigInteger. I would like many of my entities to have Time properties, but they should all work the same, the only difference being the name of the column. For instance:

class A {
Time startTime;
}
class B {
Time logOnTime;
}
...

My problem is, if I implement class Time as an @Embeddable, both entity A and B will get a column called timeValue, which is the column name found my embeddable time. If I try to redefine this name using an @AttributeOverride annotation it looks like this:

class A {
@AttributeOverride(name="timeValue", column=@Column(name="startTime", precision=17, scale=3, nullable=false, updatable=false))
private Time startTime;
}

The problem with this approach is I have to repeat the precision, scale, and other properties, and I am not too keen on repeating this information in all my entity classes.

Is there some way I can redefine the column name *only*, and still leave it up to the embeddable type to decide the precision, scale, nullability, etc.?

Thanks

Randahl


Top
 Profile  
 
 Post subject: Re: How can I avoid repeating my column definitions?
PostPosted: Sat Apr 14, 2012 11:56 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
I tried implementing a custom user type TimeType too, but that too seemed to require that I repeated column definition information all over the place, not with @AttributeOverride, but using a @Column tag.

Any clues?


Top
 Profile  
 
 Post subject: Re: How can I avoid repeating my column definitions?
PostPosted: Sat Apr 14, 2012 12:46 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
I just tried using a custom user type. I was hoping that all I had to write in each entity would be

@Type(type="iTime")
private Time startTime;

But then my big integer time value is stored with precision 19 scale 2, so I am forced to repeat this all over the place:

@Column(precision=17, scale=3)
@Type(type="iTime")
private Time startTime;

I would really like not to scatter this column definition in multiple entities. Any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.