@Embedded/@Embeddable with more complex classes?
niesar Oct 25, 2005 8:38 AMHi guys,
I'm still in the process to understand what EJB 3.0 can do for me. Right now I'm fighting with a little more complex Java Object I would like to embed in an Entity Bean.
The POJO that should be embedded looks like this
public GeoPoint {
private Latitude latitude;
private Longitude longitude;
}
Latitude and Longitude don't have any private variables and are inherited from SphericalCoordinate
public Latitude extends SphericalCoordinate // no data, just a bunch of methods
public Longitude extends SphericalCoordinate // same
public SphericalCoordinate {
private double degrees;
}
OK, now I want to embed a GeoPoint in an entity bean. So I do the following in that entity bean:
@Embedded
public GeoPoint getGeoPoint() {..}
[class GeoPoint has been tagged with annotation @Embeddable(access = AccessType.FIELD)]
The result is quite promising. I get a table created with something like
CREATE TABLE ... LATITUDE VARBIN(255), LONGITUDE VARBIN(255), ...
Now the question is how to get something like
CREATE TABLE ... LATITUDE DOUBLE, LONGITUDE DOUBLE, ... ???
I'm asking this silly question since if I'm doing the obvious I'm getting a completely unexpected result.
The code looks like this:
@Embeddable(assess=AccessType.FIELD) public GeoPoint { private Latitude latitude; private Longitude longitude; @Embedded public Latitude getLatitude() {..} @Embedded public Longitude getLongitude() {..} [...bunch of methods...] } @Embeddable public Longitude extends SphericalCoordinate { [...bunch of methods...] } @Embeddable(assess=AccessType.FIELD) public SphericalCoordinate { private double degrees; public double getDegrees() {..} [...bunch of methods...] }
Now guess what happens ;)
The automatically created table contains no sign of any GeoPoint, Latitude, Longitude or SphericalCoordinate. Simply non existent. And best of all, I can't find any log message telling me anything (although Hibernate is quite verbose otherwise)
So what is going on here?
A. Am I missunderstanding something?
B. Is the problem that there are no variables in Latitude and Longitude, so Hibernate thinks there is nothing to store anyway, so disregard it?
C. Am I in trouble because Latitude and Longitude are both inherited from SphericalCoordinate and SphericalCoordinate has the private variable called degrees? In fact I don't know how to use @AttributeOverrides/@AttributeOverride in Latitude and Longitude since there is nothing to tag with these annotations. (Originally, I wanted to check out the automatically generated names in order to use @AttributeOverrides/@AttributeOverride within GeoPoint)
D: Is it a bug?
E. Something different?
I would really appreciate if somebody could enlight me what my problem is. I really don't see it.