0

I have a table that has a column as data type number(1,0) and title as answer. This column could hold either value of 1 or 0. I have a java entity model that represents this table using hibernate (v4.1.11). I am having a difficulty in mapping number(1,0) from oracle sql to hibernate. Do I even need an annotation for it? Having int type would be suffice?

@Entity
@Table(name="FOO")
public class Foo {

    @Column(name="ANSWER")
    @<what annotation?>
    private int answer;
2
  • I just came across to a page (vladmihalcea.com/2014/06/10/…) in where it maps hibernate type to jdbc and java type. Using NumericBooleanType as annotation and change int to boolean would be right way to do it? Commented May 31, 2017 at 16:57
  • If you can change or design your data model, I would also ask you consider yes_no type which may be more suitable. Commented May 31, 2017 at 17:20

1 Answer 1

1

@Column is sufficient. Generally Type annotations are not needed unless you specifically want to override. Considering your case, it would be ideal to declare it as Boolean and use @Type NumericBooleanType or even YesNoType. If you want to override using custom type, please refer @TypeDef section in hibernate documentation https://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.