Skip to content

Is it possible for a entity to contain multiple fields of the same embeddable? #1381

Answered by nakamura-to
mazeneko asked this question in Q&A
Discussion options

You must be logged in to vote

@mazeneko We’re planning to introduce @Embedded in PR #1384 to allow you to specify a prefix. Here’s an example of how it will work:

@Embeddable
public record Address(String street, String city, String zipCode) {}

@Entity
public class Customer {
    @Id Integer customerId;
    
    @Embedded(prefix = "billing_")
    Address billingAddress;
    
    @Embedded(prefix = "shipping_") 
    Address shippingAddress;
}

This creates columns: billing_street, billing_city, billing_zip_code, shipping_street, shipping_city, shipping_zip_code.

Would this feature meet your needs? Please feel free to leave any comments or questions.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nakamura-to
Comment options

@mazeneko
Comment options

@nakamura-to
Comment options

Answer selected by mazeneko
@mazeneko
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants