-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: OneToMany: FK wird nicht automatisch gesetzt
PostPosted: Thu Feb 09, 2006 9:53 am 
Newbie

Joined: Wed Feb 08, 2006 4:21 am
Posts: 1
Ich implementiere ein OneToMany-Association (Cascade.ALL).

[LayoutElem] one----many [LayoutLabelElem]


Wenn ich den FK (layoutId) in der "many"-Klasse nicht anführe wird er trotzdem inkl. Constraint in der Datenbank erstellt.

Beim speichern der "one"-Klasse mit bleibt in der "many"-Tabelle die Spalte layoutid nicht gesetzt, was dem SQL-output entspricht:
Code:
Hibernate: insert into LayoutLabelElem (name, TYPE, id) values (?, 'at.onlinegroup.charta.elem.LayoutLabelElem', null)


Da ich im Tutorial
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#example-parentchild
keinen Hinweis auf ein explizites setzen des FK gefunden habe, nehme ich an das Hibernate3 es unterstützt (richig?).
Mir unklar warum in meinem Fall der FK nicht gestzt wird.

Ich bitte um Hilfe oder einen Verweis zur entsprechenden Doku.
Vielen Dank

Hibernate version: 3.1.2

Mapping documents:
LayoutElem.class
Code:
@Entity
@Table(name="layout")
public class LayoutElem {
  private int layoutId;
  private String name;
  private Map<String, LayoutLabelElem> labels;
  ...
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  public int getLayoutId() { return layoutId; }
  ...
  @OneToMany(mappedBy="layoutId", cascade = CascadeType.ALL)
  @MapKey
  @JoinColumn(name="layoutId")
  @OnDelete(action=OnDeleteAction.CASCADE)
  public Map<String,LayoutLabelElem> getLabels() { return labels; }
  ...

LayoutLabelElem.class
Code:
@Entity
@Table(name="layoutlabel")
public class LayoutLabelElem {
  private int id;
  //public int layoutId;
  public double x = 0;
  public double y = 0;
  public String fontName = "";
  ...
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  public int getId() { return id; }
  ...


Name and version of the database you are using:
hsqldb 1.8.0


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 5:28 am 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
Hi,

Quote:
@JoinColumn(name="layoutId")

kommt typischerweise in Bidirektionalen Assoziationen auf der @ManyToOne Seite zum Einsatz (siehe
http://www.hibernate.org/hib_docs/annot ... ollections)


Gruß,
Micha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.