Answer the question
In order to leave comments, you need to log in
Why can't an entity class exist inside another entity class?
There are 2 entity classes:
1) Point (point)
package entity;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Point {
@Id
private int id;
private int x;
private int y;
public Point() {
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
package entity;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* Entity-класс "Четырехугольник"
*/
@Entity
public class Quadrangle {
@Id
private int id;
public Quadrangle() {
}
public Quadrangle(Point p1, Point p2, Point p3, Point p4) {
}
@Override
public String toString() {
return "Quadrangle id #" + id;
}
}
Answer the question
In order to leave comments, you need to log in
Why not?
It is quite possible - a One-To-One connection is created, and forward. What is the problem?
These annotations are ultimately needed to describe the relationship between database entities.
One entity can be nested within another, but the relationship between them must be specified.
There is a description here:
https://www.tutorialspoint.com/jpa/jpa_entity_rela...
See annotations:
@ManyToOne Relation
@OneToMany Relation
@OneToOne Relation
@ManyToMany Relation
My answer is not exactly the answer to your question...
but if you want to describe the essence of some geographic object and store it in the database, then look towards WKT || JTS.
For example, MULTIPOLYGON (30 31, 29 28, 27 26, 24 23)
instead of Quadrangle
Well, POINT (30 31)
instead of Point
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question