JPA 2.0: @AttributeOverrides und geerbte Attribute nicht kommen gut mit einander

Ich brauche Hilfe für das nächste problem, die scheint ganz ähnlich wie dieses ein. Aber die vorgeschlagene Lösung funktioniert nicht in meinem Fall. Ich habe die Klasse RoadDistance, die tagged as @Embbedable und die Klasse RoadMetricLoader, das ist @Embbedable zu und enthält zwei Attribute vom Typ RoadDistante. Es ist auch die Klasse RoadConnection, das ist eine Einheit, und enthält ein Attribut vom Typ RoadmetricLoader. Ich bin nicht erfolgreich im überschreiben der Attribute (@AttributeOverride) von RoadMetricLoader für die Klasse RoadDistance (ich komme nicht auf die Felder ROAD_ESTIMATED_DISTANCE_VALUE, ROAD_ESTIMATED_DISTANCE_UNIT_ID, ROAD_REAL_DISTANCE_VALUE und ROAD_REAL_DISTANCE_UNIT_ID in der Tabelle ROAD_CONNECTION)

Die Datenbank ist MySQL 5.2.21 und die verwendeten Bibliotheken für JPA 2.0, diejenigen sind, die von EclipseLink 2.4.1

Ich habe versucht, verschiedene Optionen, aber keiner von Ihnen arbeiten. Ich zeigen Sie alle Optionen im kommentierten Blöcke in dem code, den Sie unten sehen können. Wenn unkommentierte einer option halten, die andere kommentiert. Diese sind das Ergebnis bekomme ich in jedem Fall:

OPTION 1: Es hat keine Fehler, aber in der Tabelle ROAD_CONNECTION bekomme ich nur zwei fieds: WERT und UNIT_ID.

OPTION 2: Das gleiche Ergebnis wie Variante 1.

OPTION 3: es war meine erste Wette (siehe offizielle Dokumentation Beispiel 2, und die bereits angegebenen link oben), aber ich bekomme den nächsten Fehler

Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@138d107f
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [jamUnit] failed.
Internal Exception: Exception [EclipseLink-7309] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute named [estimatedRoadDistance.unit] from the embeddable class [class net.question.RoadMetricLoader] is not a valid mapping to use with an attribute override for the attribute [metricLoader] on class [class net.question.RoadConnection].
    at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:118)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    (...)

OPTION 4: Die gleiche wie OPTION 1 und 2.

OPTION 5:

Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@12360be0
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [jamUnit] failed.
Internal Exception: Exception [EclipseLink-7309] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute named [unit] from the embeddable class [class net.question.RoadDistance] is not a valid mapping to use with an attribute override for the attribute [estimatedRoadDistance] on class [class net.question.RoadMetricLoader].
    at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:118)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    (...)

@Entity
@Table(name="UNIT")
public class Unit {

    private Long id;
    private String name;
    private String measureSystemCode;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="UNIT_SEQ_GENERATOR")
    @SequenceGenerator(name="UNIT_SEQ_GENERATOR", sequenceName="UNIT_SEQ")
    @Column(name = "ID")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "NAME", nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "MEASURE_SYSTEM_CODE", nullable = false)
    public String getMeasureSystemCode() {
        return measureSystemCode;
    }

    public void setMeasureSystemCode(String measureSystemCode) {
        this.measureSystemCode = measureSystemCode;
    }

}

@MappedSuperclass
public abstract class Metric<V extends Comparable<V>> {

    private V value;
    private Unit unit;

    @Column(name = "VALUE", nullable = false)
    public V getValue() {
        return value;
    }

    public void setValue(V value) {
        this.value = value;
    }

    @ManyToOne
    @JoinColumn(name = "UNIT_ID", nullable = false)
    public Unit getUnit() {
        return unit;
    }

    public void setUnit(Unit unit) {
        this.unit = unit;
    }

}

@MappedSuperclass
public abstract class ScalarPhysicalMetric<M extends Number & Comparable<M>>
extends Metric<M> {

}

@Embeddable
public final class RoadDistance extends ScalarPhysicalMetric<Double> {

}

/*
//-##----------- OPTION 4 ---------->
@AttributeOverrides({
    @AttributeOverride(name = "estimatedRoadDistance.value", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_VALUE")),
    @AttributeOverride(name = "estimatedRoadDistance.unit", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_UNIT_ID")),
    @AttributeOverride(name = "realRoadDistance.value", column = @Column(name = "ROAD_REAL_DISTANCE_VALUE")),
    @AttributeOverride(name = "realRoadDistance.unit", column = @Column(name = "ROAD_REAL_DISTANCE_UNIT_ID"))
})
//<---------- OPTION 4 -----------##-
*/
@Embeddable
public final class RoadMetricLoader {

    private RoadDistance estimatedRoadDistance;
    private RoadDistance realRoadDistance;

    @Embedded
    /*
    //-##----------- OPTION 5 ---------->
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_VALUE")),
        @AttributeOverride(name = "unit", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_UNIT_ID"))
    })
    //<---------- OPTION 5 -----------##-
    */
    public RoadDistance getEstimatedRoadDistance() {
        return estimatedRoadDistance;
    }

    public void setEstimatedRoadDistance(RoadDistance estimatedRoadDistance) {
        this.estimatedRoadDistance = estimatedRoadDistance;
    }

    @Embedded
    /*
    //-##----------- OPTION 5 ---------->
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "ROAD_REAL_DISTANCE_VALUE")),
        @AttributeOverride(name = "unit", column = @Column(name = "ROAD_REAL_DISTANCE_UNIT_ID"))
    })
    //<---------- OPTION 5 -----------##-
    */
    public RoadDistance getRealRoadDistance() {
        return realRoadDistance;
    }

    public void setRealRoadDistance(RoadDistance realRoadDistance) {
        this.realRoadDistance = realRoadDistance;
    }

}

//-##----------- OPTION 1 ---------->
/*
@AttributeOverrides({
    @AttributeOverride(name = "estimatedRoadDistance.value", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_VALUE")),
    @AttributeOverride(name = "estimatedRoadDistance.unit", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_UNIT_ID")),
    @AttributeOverride(name = "realRoadDistance.value", column = @Column(name = "ROAD_REAL_DISTANCE_VALUE")),
    @AttributeOverride(name = "realRoadDistance.unit", column = @Column(name = "ROAD_REAL_DISTANCE_UNIT_ID"))
})
//<---------- OPTION 1 -----------##-
*/
/*
//-##----------- OPTION 2 ---------->
@AttributeOverrides({
    @AttributeOverride(name = "metricLoader.estimatedRoadDistance.value", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_VALUE")),
    @AttributeOverride(name = "metricLoader.estimatedRoadDistance.unit", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_UNIT_ID")),
    @AttributeOverride(name = "metricLoader.realRoadDistance.value", column = @Column(name = "ROAD_REAL_DISTANCE_VALUE")),
    @AttributeOverride(name = "metricLoader.realRoadDistance.unit", column = @Column(name = "ROAD_REAL_DISTANCE_UNIT_ID"))
})
//<---------- OPTION 2 -----------##-
*/
@Entity
@Table(name="ROAD_CONNECTION")
public class RoadConnection {

    private Long id;
    private String pointA;
    private String pointB;
    private RoadMetricLoader metricLoader;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="ROAD_CONNECTION_SEQ_GENERATOR")
    @SequenceGenerator(name="ROAD_CONNECTION_SEQ_GENERATOR", sequenceName="ROAD_CONNECTION_SEQ")
    @Column(name = "ID")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "POINT_A", nullable = false)
    public String getPointA() {
        return pointA;
    }

    public void setPointA(String pointA) {
        this.pointA = pointA;
    }

    @Column(name = "POINT_B", nullable = false)
    public String getPointB() {
        return pointB;
    }

    public void setPointB(String pointB) {
        this.pointB = pointB;
    }

    /*
    //-##----------- OPTION 3 ---------->
    @AttributeOverrides({
        @AttributeOverride(name = "estimatedRoadDistance.value", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_VALUE")),
        @AttributeOverride(name = "estimatedRoadDistance.unit", column = @Column(name = "ROAD_ESTIMATED_DISTANCE_UNIT_ID")),
        @AttributeOverride(name = "realRoadDistance.value", column = @Column(name = "ROAD_REAL_DISTANCE_VALUE")),
        @AttributeOverride(name = "realRoadDistance.unit", column = @Column(name = "ROAD_REAL_DISTANCE_UNIT_ID"))
    })
    //<---------- OPTION 3 -----------##-
    */
    @Embedded
    public RoadMetricLoader getMetricLoader() {
        return metricLoader;
    }

    public void setMetricLoader(RoadMetricLoader metricLoader) {
        this.metricLoader = metricLoader;
    }

}
InformationsquelleAutor GYLZ | 2013-01-20
Schreibe einen Kommentar