Think about this class:
@Entity
class Bar {
@Id
private long id;
private FooId fooId;
/* ... */
}
Where Foo
is essentially just:
class FooId {
private String id;
/* ... */
}
I (obviously) obtain the error that "Fundamental characteristics are only able to constitute the next types: ...".
It is possible to method to tell JPA (or EclipseLink) to deal with my fooId
area in Bar
like a String?
The main reason I am with a couple "wrapper" type rather than an ordinary String is the fact that I wish to enforce a little of type-safety during my APIs.
E. g. getAllFooWithBaz(FooId fooId, BazId bazId)
rather than getAllFooWithBaz(String fooId, String bazId)
.
Or it is possible to better way to accomplish this?
This can be a common requirement. Do this:
@Entity
class Bar {
@EmbeddedId
private FooId fooId;
/* ... */
}
and:
@Embeddable
class FooId {
private String id;
/* ... */
}
or (underlying database schema and FooId
stay the same):
@Entity
@IdClass(FooId.class)
class Bar {
@Id
private String fooId;
/* ... */
}