PDA

View Full Version : Help: usage of JPA annotations @ManyToOne @JoinColumn Hibernate


aness2
08-09-2009, 10:34 PM
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.

@<hidden>
@<hidden>(name="T_MEASUREMENT")
@<hidden>(strategy=InheritanceType.SINGLE_TABLE)
@<hidden>(name="DISCRIMINATOR", discriminatorType=DiscriminatorType.STRING)
public class Measurement {

@<hidden>
@<hidden>(name="MEASUREMENT_ID")
private String id; //measurement_id/primary key

@<hidden> //bi-directional many-to-one association to Metric
@<hidden>(name="METRIC_ID")
private Metric <b>metricObject</b>;

...

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

@<hidden>
@<hidden>(name="T_METRIC")
public class Metric {

@<hidden>
@<hidden>(name="METRIC_ID")
private String id;

@<hidden>(name="METRIC_NAME")
private String name;

//bi-directional many-to-one association to MetricType
@<hidden>
@<hidden>(name="METRIC_TYPE_ID")
private MetricType metricType;

@<hidden>(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 (<b>metricObject_METRIC_ID</b>, timestamp, VALUE_LONG, DISCRIMINATOR, MEASUREMENT_ID) values (?, ?, ?, 'VALUE_LONG', ?)

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

Does anyone know what I'm doing wrong?

Thank you for your answers!

aness2

vseehua
09-09-2009, 12:08 AM
Hello aness2. I am thinking that you may have confused the meaning of JPA within the context of this forum with something related to programming. JPA here refers to Jabatan Perkhidmatan Awam or the Public Services Department of Malaysia. Since this is a forum for Malaysian students most are more concerned with the scholarships provided by JPA.

Nevertheless, I have moved your thread to the programming and web development section as there are several programming wizards in ReCom as well. Hope they are able to provide the answers you needed.

Cheers,
C

youngyew
09-09-2009, 06:45 AM
I was totally puzzled before vseehua pointed out the misunderstanding. :D