2

I have this object

@Entity
public class Cat {
  @Id String name;
  Fur fur;
}

public class Fur {
  String color1;
  String color2;
}

How do I map it to:

 Name      Color1 Color2
+---------+------+------+
|SnowBall |red   |green |
+---------+------+------+
|Snowball2|white |black |
+---------+------+------+

I only have JPA 2.1

1 Answer 1

4

You could use @Embeddable and @Embedded JPA annotations.

@Entity
public class Cat {
  @Id String name;
  @Embedded
  Fur fur;
}

@Embeddable
public class Fur {
  String color1;
  String color2;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I will have a look at that.

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.