Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3991252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:35:35+00:00 2026-05-20T06:35:35+00:00

I have a class which contains a number of fields, and all are annotated

  • 0

I have a class which contains a number of fields, and all are annotated by property. For one of those fields, though, I want to present a double to the database and a Date to the user.

I’ve tried any number of combinations here but hbm2ddl (and thus, hibernate) keep treating the dwell property as a timestamp. How should I be implementing this if not via annotations similar to what I have below (this is a simplified version of the class in question)?

I’d consider moving all the annotations to fields, but the class that needs this sits at the top of an inheritance hierarchy involving another 25 classes and many, many annotations. It would take the better part of a day to move all the annotations and that seems like an inelegant way to deal with this.

@Entity
@AccessType("property")
public class Test {

    private long id;
    private Double dwell;

    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @NotNull
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @AccessType("field")
    @Column(name = "DWELL_ID", precision = 10, scale = 3)
    public Date getDwell() {
        return new Date();
    }

    public void setDwell(Double dwell) {
        this.dwell = dwell;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:35:36+00:00Added an answer on May 20, 2026 at 6:35 am

    This looks a bit strange. I’m not sure that changing the access type will actually work for you.

    You are breaking the javabeans convention, which is risky. Don’t do it – let getters and setters be purely getters and setters, without hidden extras like constructing objects.

    I would just write another method – getDwellAsDate() and do the conversion there. You can also define a custom hibernate Type to handle that (but it’s not worth it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which contains a static collection that can be used across
I have a class which contains 5 properties. If any value is assingned to
I have a parent class which contains a child object. I am using set
I have an abstract class which contains method for setting header text. It looks
Alright so here is the question. I have a user class which contains a
I have a class library project which contains some content files configured with the
In my console application have an abstract Factory class Listener which contains code for
I have an Entity class, which contains 3 pointers: m_rigidBody, m_entity, and m_parent. Somewhere
I have a DLL which contains a class with static members . I use
I have a business object project, which contains composite structure: public class Tree {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.