usage JPA annotations @ManyToOne @JoinColumn Hibernate

View: New views
1 Messages — Rating Filter:   Alert me  

usage JPA annotations @ManyToOne @JoinColumn Hibernate

by aness2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi at all,

I have a configuration problem with JPA. I have a class Measurement which is referencing a class Metric. In my database the tables T_Measurement and T_Metric. T_Measurement references the primary key METRIC_ID from T_Metric. I have problems to reflect this structure in JPA.

@Entity
@Table(name="T_MEASUREMENT")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="DISCRIMINATOR", discriminatorType=DiscriminatorType.STRING)
public class Measurement {
       
        @Id
        @Column(name="MEASUREMENT_ID")
        private String id; //measurement_id/primary key
       
        @ManyToOne //bi-directional many-to-one association to Metric
        @JoinColumn(name="METRIC_ID")
        private Metric metricObject;

...

-------------------

@Entity
@Table(name="T_METRIC")
public class Metric {
       
        @Id
        @Column(name="METRIC_ID")
        private String id;
       
        @Column(name="METRIC_NAME")
        private String name;
       
        //bi-directional many-to-one association to MetricType
        @ManyToOne
        @JoinColumn(name="METRIC_TYPE_ID")
        private MetricType metricType;
       
        @OneToMany(mappedBy = "metricObject") //bi-directional many-to-one association to Measurement
        private Set<Measurement> measurements = new HashSet<Measurement>();

...

-------------------

Hibernate always references false column name:
DEBUG [main] org.hibernate.SQL: insert into T_MEASUREMENT (metricObject_METRIC_ID, timestamp, VALUE_LONG, DISCRIMINATOR, MEASUREMENT_ID) values (?, ?, ?, 'VALUE_LONG', ?)

I would like to have: insert into T_MEASUREMENT (METRIC_ID, timestamp, VALUE_LONG, DISCRIMINATOR, MEASUREMENT_ID) values (?, ?, ?, 'VALUE_LONG', ?)

Does anyone know what I'm doing wrong?

Thank you for your answers!

aness2