Reputation: 281
Is the following code legal:
@Entity
@Embeddable
public class UserProfile {
@Id
private String name;
private String pass;
..
}
Can I use both annotations at once?
Upvotes: 2
Views: 672
Reputation: 268
no, se here http://www.objectdb.com//api/java/jpa how to do it
other thing, the id is automatic generated, but yes you can change as you want ;)
Upvotes: 2
Reputation: 516
Ok, we are confusing things here.
An entity is a java class for whose instances you want persistence in the db in the form of one table per entity, a row per instance.
Other instances of other classes can either be entities with their own tables and linked with the one to many, many to many, and such annotations, or they can be "embedded" directly inside the same table of another entity. This is most useful when you have complex keys and you need separate classes to define the primary keys.
So, either you have an embeddable class whose instances will be persisted inside another entity, or you have an entity that will be persisted to its own table.
Upvotes: 0
Reputation: 6685
No. Embeddables are designed to be embedded into entities. They are used to implement the composition pattern.
Upvotes: 0
Reputation: 5780
Why must there always be people who, when instructed not to press a button, will do it just to see what happens? Embeddable is a type, just like Entity and should not be used together, since by definition, an Embeddable cannot have an Id.
Upvotes: 4