Hallo,
ich versuche gerade mittels Hibernate eine Relationstabelle zwischen 2 Tabellen zum laufen zu bringen.
Die Entitys schauen so aus:
Composite Key:
Kompilieren tut das ganze einwandfrei, wenn ich aber jetzt ein "participance" - Objekt speichern möchte (mit getHibernateTemplate().saveOrUpdate(participance) bekomme ich folgende Exception:
Weiß jemand was ich da falsch mache?
Das mit dem zusammengesetzten Key hab ich von hier: MAD Code Monkeys: Hibernate annotations: The composite primary key with foreign keys references
Vielen Dank,
lg
ich versuche gerade mittels Hibernate eine Relationstabelle zwischen 2 Tabellen zum laufen zu bringen.
Die Entitys schauen so aus:
Code:
1:n n:1
Event <--------------------> Participance <------------------------> Participant
pk_event id_event/id_part pk_part
Java:
@Entity
@SuppressWarnings("serial")
@Table(name="TEvent")
public class Event implements Serializable {
private Integer pk_event;
private String eventname;
private Timestamp eventtime;
private Integer fee;
public Event() {}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Integer getPk_event() {
return pk_event;
}
public void setPk_event(final Integer pk_event) {
this.pk_event = pk_event;
}
@ManyToMany(
fetch=FetchType.EAGER,
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
mappedBy = "events",
targetEntity = Runningmode.class)
public Collection<Runningmode> getRunningmodes() {
return runningmodes;
}
...
Java:
@Entity
@Table(name="TParticipance")
public class Participance implements Serializable {
@Id
private ParticipantEventPK participantEventPK = new ParticipantEventPK();
@SuppressWarnings("unused")
@Column(name="id_event", nullable=false, updatable=false, insertable=false)
private Integer id_event;
@SuppressWarnings("unused")
@Column(name="id_part", nullable=false, updatable=false, insertable=false)
private Integer id_part;
private Boolean paid;
private float paidvalue;
private String paidPer;
private Participant participant;
private Event event;
public Participance() {}
public void setParticipantEventPK(ParticipantEventPK participantEventPK) {
this.participantEventPK = participantEventPK;
}
public ParticipantEventPK getParticipantEventPK() {
return participantEventPK;
}
public Participant getParticipant() {
return participant;
}
public void setParticipant(final Participant participant) {
this.participant = participant;
}
public Event getEvent() {
return event;
}
public void setEvent(final Event event) {
this.event = event;
}
...
Composite Key:
Java:
@Embeddable
public class ParticipantEventPK implements Serializable {
@ManyToOne
private Participant participant;
@ManyToOne
private Event event;
public ParticipantEventPK() {
}
public Participant getParticipant() {
return participant;
}
public void setParticipant(Participant participant) {
this.participant = participant;
}
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
}
Java:
@Entity
@SuppressWarnings("serial")
@Table(name="TParticipant")
public class Participant implements Serializable {
private Integer pk_part;
private String firstname;
public Participant() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Integer getPk_part() {
return pk_part;
}
public void setPk_part(final Integer pk_part) {
this.pk_part = pk_part;
}
...
Kompilieren tut das ganze einwandfrei, wenn ich aber jetzt ein "participance" - Objekt speichern möchte (mit getHibernateTemplate().saveOrUpdate(participance) bekomme ich folgende Exception:
Code:
Exception class RegistrationService, Method saveRegistrationData:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not retrieve snapshot:
[at.myappl.participant.domain.Participance#component[event,participant]{event=null,
participant=null}]; SQL [select participan_.event_pk_event, participan_.participant_pk_part, participan_.bruttostarttime as bruttost1_2_, participan_.bruttotime as bruttotime2_,
participan_.endtime as endtime2_, participan_.event as event2_, participan_.meantime1 as
meantime7_2_, participan_.meantime2 as meantime8_2_, participan_.meantime3 as meantime9_2_,
participan_.meantime4 as meantime10_2_, participan_.meantime5 as meantime11_2_,
participan_.nettotime as nettotime2_, participan_.paid as paid2_, participan_.paidPer as paidPer2_,
participan_.paidvalue as paidvalue2_, participan_.participant as partici16_2_, participan_.runningmode
as running17_2_, participan_.starttime as starttime2_ from TParticipance participan_ where
participan_.event_pk_event=? and participan_.participant_pk_part=?]; nested exception is
org.hibernate.exception.SQLGrammarException: could not retrieve snapshot:
[at.myappl.participant.domain.Participance#component[event,participant]{event=null, participant=null}]
19.04.2011 06:54:52 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 1054, SQLState: 42S22
19.04.2011 06:54:52 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Unknown column 'participan_.event_pk_event' in 'field list'
Weiß jemand was ich da falsch mache?
Das mit dem zusammengesetzten Key hab ich von hier: MAD Code Monkeys: Hibernate annotations: The composite primary key with foreign keys references
Vielen Dank,
lg