1

how can we generate table using custom object attribute as table column

private class CustomObject {   
    String attr1;
    String attr2;
}
@Entity
@Table(name = "result")
public class Result {
   @Column
   private  String id;

   @Column
   public CustomObject cobject;
}

RESULT table generate as follow

id attr1 attr2
2
  • 1
    You're looking for @Embedded. Commented Sep 21, 2021 at 6:50
  • thank you @chrylis-cautiouslyoptimistic- Commented Sep 22, 2021 at 15:18

1 Answer 1

1

From Hibernate_User_Guide documentation:

PA defines two terms for working with an embeddable type: @Embeddable and @Embedded. @Embeddable is used to describe the mapping type itself (e.g. Publisher).@Embedded is for referencing a given embeddable type (e.g. book.publisher).

So you can annotate your classes like below:

@Embeddable
private class CustomObject {   
    String attr1;
    String attr2;
}

@Entity
@Table(name = "result")
public class Result {
   @Column
   private  String id;

   @Embedded
   public CustomObject cobject;
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you @dariosicily
@try_aaam You are welcome.

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.